Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

How to make ComboBox highlight color to none?

Posted by Paul on February 24, 2011


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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s