MoonSelect.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Drawing;
  2. using System.Windows.Forms;
  3. namespace Optimizer
  4. {
  5. public sealed class MoonSelect : ComboBox
  6. {
  7. private const int WM_PAINT = 0xF;
  8. private int buttonWidth = SystemInformation.HorizontalScrollBarArrowWidth;
  9. Color borderColor = Color.Blue;
  10. public Color BorderColor
  11. {
  12. get { return borderColor; }
  13. set { borderColor = value; Invalidate(); }
  14. }
  15. protected override void WndProc(ref Message m)
  16. {
  17. base.WndProc(ref m);
  18. if (m.Msg == WM_PAINT && DropDownStyle != ComboBoxStyle.Simple)
  19. {
  20. using (var g = Graphics.FromHwnd(Handle))
  21. {
  22. var adjustMent = 0;
  23. if (FlatStyle == FlatStyle.Popup ||
  24. (FlatStyle == FlatStyle.Flat &&
  25. DropDownStyle == ComboBoxStyle.DropDownList))
  26. adjustMent = 1;
  27. var innerBorderWisth = 3;
  28. var innerBorderColor = BackColor;
  29. if (DropDownStyle == ComboBoxStyle.DropDownList &&
  30. (FlatStyle == FlatStyle.System || FlatStyle == FlatStyle.Standard))
  31. innerBorderColor = Color.FromArgb(0xCCCCCC);
  32. if (DropDownStyle == ComboBoxStyle.DropDownList && !Enabled)
  33. innerBorderColor = SystemColors.Control;
  34. if (DropDownStyle == ComboBoxStyle.DropDownList || Enabled == false)
  35. {
  36. using (var p = new Pen(innerBorderColor, innerBorderWisth))
  37. {
  38. p.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
  39. g.DrawRectangle(p, 1, 1,
  40. Width - buttonWidth - adjustMent - 1, Height - 1);
  41. }
  42. }
  43. using (var p = new Pen(BorderColor))
  44. {
  45. g.DrawRectangle(p, 0, 0, Width - 1, Height - 1);
  46. g.DrawLine(p, Width - buttonWidth - adjustMent,
  47. 0, Width - buttonWidth - adjustMent, Height);
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }