code_junkie

Changing the color of ComboBox's highlighter in C#

Nov 12th, 2011
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
  2. {
  3. e.DrawBackground();
  4. int index = e.Index;
  5. CombinationEntry aFunction = comboBox1.Items[index] as CombinationEntry; //CombinationEntry is a custom object to hold the gray info. Gray if not available and black if available
  6. if (aFunction.myIsAvailable)
  7. {
  8. e.Graphics.DrawString(aFunction.ToString(), new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.Black, new Point(e.Bounds.X, e.Bounds.Y));
  9. }
  10. else
  11. {
  12. e.Graphics.DrawString(aFunction.ToString(), new Font("Arial", 10, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.Gray, new Point(e.Bounds.X, e.Bounds.Y));
  13. }
  14. }
  15.  
  16. SystemColors.WindowText
  17.  
  18. SystemColors.HighlightText
  19.  
  20. e.State == DrawItemState.Selected ?
  21. SystemBrushes.HighlightText : SystemBrushes.WindowText
  22.  
  23. SystemBrushes.GrayText
  24.  
  25. comboBox1.Font
  26.  
  27. if (e.State == ((DrawItemState.NoAccelerator | DrawItemState.NoFocusRect) |
  28. (DrawItemState.Selected |
  29. DrawItemState.NoAccelerator |
  30. DrawItemState.NoFocusRect)))
  31. {
  32. e.Graphics.DrawString(aFunction.ToString(),
  33. new Font("Arial", 10, FontStyle.Regular,
  34. GraphicsUnit.Pixel),
  35. SystemBrushes.HighlightText,
  36. new Point(e.Bounds.X, e.Bounds.Y));
  37. }
Add Comment
Please, Sign In to add comment