I'm losing the bottom of the character when displaying in a multi-color, selected item bold, listbox

Hi,  I'm having a problem with the following code.  It successfully lets me display individual items in a listbox in any color I choose, and it will highlight the selected item by writing it as bold.  The problem is that it is chopping off the bottom of the characters.  Characters like 'g' and y' get screwed up, presumably because they get overwritten when I call FillRectangle for the item which follows.

Does anyone have any ideas?  Obviously it involves the fact that I'm filling a rectangle with
Brushes.Green before I write the string.  But I can't think of any way around this.

Thanks,
Bob

private void ordersListBox_DrawItem(object sndr, System.Windows.Forms.DrawItemEventArgs e)
{
    //
    // Draw the background of the ListBox control for each item.
    // Create a new Brush and initialize to a Black colored brush by default.
    //
    e.DrawBackground();
// here you can set the colors to anything you want
    Brush fontBrush = Brushes.Black;
    Brush backBrush = Brushes.Green;
    Font boldFont = new Font(e.Font, FontStyle.Bold);

    Font font = e.Font;
    if ( e.Index == ordersListBox.SelectedIndex )
        font = boldFont;
            
    e.Graphics.FillRectangle(backBrush, e.Bounds);
    e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), font,      
             fontBrush,e.Bounds,StringFormat.GenericDefault);
               
    //
    // If the ListBox has focus, draw a focus rectangle around the selected item.
    //
    e.DrawFocusRectangle();
}
ba272Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
For owner-drawn control you need to handle also MeasureItem. In this event handler supply item height which is enough to show all string.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ba272Author Commented:
I see how to to create a MeasureItem event, but I can't seem to get it to reach my breakpoint inside it.  Is there someting I need to do in order to make this event fire?

Thanks.
0
AlexFMCommented:
DrawMode property of listbox should be OwnerDrawVariable.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.