How to make ComboBox highlight color to none?

In some forums I have seen developers wanted to change the selected color (usually Blue) of ComboBox to normal background color. I would like to add the code for following.

Custom Drawing

The method used for accomplishing this is Custom Drawing.

Steps

1. Create a new windows application and place a combo box on the form

2. Set the property DrawMode to OwnerDrawVariable

3. On the combo box DrawItem event, add the following code:

private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)

{

ComboBox combo = sender as ComboBox;

e.Graphics.FillRectangle(new SolidBrush(combo.BackColor), e.Bounds);

e.Graphics.DrawString(combo.Items[e.Index].ToString(), e.Font, new

SolidBrush(combo.ForeColor), new Point(e.Bounds.X, e.Bounds.Y));

}

Testing the Application

You can add some test data items to the combox and run the application.

clip_image002

Now you can see that eventhough the mouse is on the dropdown list area the highlight color is not there.

Leave a Reply

Your email address will not be published. Required fields are marked *