Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change color of a combo box ITEM on hover

Status
Not open for further replies.

sajidi99

Programmer
Jun 7, 2005
53
SE

Hello,

Can someone tell me how to change the text color of a combo box item when mouse hovers on it?

Thanks
 
Use the DrawItem event to draw the items the way you want. In the example below, the second item in the combo list is drawn in red when the mouse hover over it. (Don't forget to set the DrawMode property of the combo to OwnerDrawFixed).
Code:
void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
		{
			e.DrawBackground();

			if (e.Index == 1 && (e.State & DrawItemState.Selected) == DrawItemState.Selected)
			{
				e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(), comboBox1.Font, Brushes.Red, e.Bounds);
			}

			else
			{
				e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(), comboBox1.Font, Brushes.Black, e.Bounds);
			}
		}
 
Thanks very much mate, thats exactly what I needed.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top