MoonSelect.cs 2.1 KB

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