MoonList.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Drawing;
  2. using System.Windows.Forms;
  3. namespace Optimizer
  4. {
  5. public sealed class MoonList : ListBox
  6. {
  7. public MoonList()
  8. {
  9. this.DrawMode = DrawMode.OwnerDrawVariable;
  10. this.BorderStyle = BorderStyle.None;
  11. this.MeasureItem += MoonListBox_MeasureItem;
  12. this.DrawItem += MoonListBox_DrawItem;
  13. }
  14. private void MoonListBox_DrawItem(object sender, DrawItemEventArgs e)
  15. {
  16. if (e.Index < 0) return;
  17. if (this.Items.Count <= 0) return;
  18. e.DrawBackground();
  19. Brush myBrush = new SolidBrush(Color.White);
  20. if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
  21. {
  22. e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(50, 50, 50)), e.Bounds);
  23. }
  24. else
  25. {
  26. e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(20, 20, 20)), e.Bounds);
  27. }
  28. e.Graphics.DrawString(this.Items[e.Index].ToString(), this.Font, myBrush, e.Bounds);
  29. e.DrawFocusRectangle();
  30. }
  31. private void MoonListBox_MeasureItem(object sender, MeasureItemEventArgs e)
  32. {
  33. e.ItemHeight = this.Font.Height;
  34. }
  35. }
  36. }