MoonList.cs 1.2 KB

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