In a winform application running on windows 7 I want the change the background color of a combobox to highlight it. The comboxbox has a DropDownStyle of DropDownList.
<
Here is what i used for a vb project for another beginner that might be interested. One can use the sender of the event as the combobox that triggered it. By casting it, you can have access to the elements of the list. I also changed the graphics TextRenderingHint for better font display.
Private Sub PaintComboBoxItem(sender As Object, e As DrawItemEventArgs)
Dim combobox As ComboBox = sender
Dim index As Integer = If(e.Index >= 0, e.Index, 0)
Dim brush As Brush = If(combobox.Enabled,
New SolidBrush(m_UITheme.TitleColor),
New SolidBrush(m_UITheme.White))
e.Graphics.SmoothingMode = SmoothingMode.HighQuality
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
e.DrawBackground()
e.Graphics.DrawString(combobox.Items(index).ToString(), combobox.Font, brush, e.Bounds, StringFormat.GenericDefault)
e.DrawFocusRectangle()
End Sub