1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217:
| [ToolboxItem(true)] public class WindowsDefaultTitleBarButton : NoFocusCueBotton { public enum Type { Close, Maximize, Minimize }
[EditorBrowsable(EditorBrowsableState.Always)] [Browsable(true)] [DefaultValue(Type.Close)] [Category("Appearance")] [Description("The type which defines the buttons behaviour.")] public Type ButtonType { get; set; }
[EditorBrowsable(EditorBrowsableState.Always)] [Browsable(true)] [DefaultValue(null)] [Category("Appearance")] [Description("The background color of the button when the mouse is inside the buttons bounds.")] public Color HoverColor { get; set; }
[EditorBrowsable(EditorBrowsableState.Always)] [Browsable(true)] [DefaultValue(null)] [Category("Appearance")] [Description("The background color of the button when the button is clicked.")] public Color ClickColor { get; set; }
[EditorBrowsable(EditorBrowsableState.Always)] [Browsable(true)] [DefaultValue(null)] [Category("Appearance")] [Description("The default color of the icon.")] public Color IconColor { get; set; }
[EditorBrowsable(EditorBrowsableState.Always)] [Browsable(true)] [DefaultValue(null)] [Category("Appearance")] [Description("The color of the icon when the mouse is inside the buttons bounds.")] public Color HoverIconColor { get; set; }
[EditorBrowsable(EditorBrowsableState.Always)] [Browsable(true)] [DefaultValue(null)] [Category("Appearance")] [Description("The color of the icon when the button is clicked.")] public Color ClickIconColor { get; set; }
[EditorBrowsable(EditorBrowsableState.Never)] [Browsable(false)] public virtual Color ActiveColor { get { if (this.Clicked) return this.ClickColor;
if (this.Hovered) return this.HoverColor;
return BackColor; } }
[EditorBrowsable(EditorBrowsableState.Never)] [Browsable(false)] public virtual Color ActiveIconColor { get { if (this.Clicked) return this.ClickIconColor;
if (this.Hovered) return this.HoverIconColor;
return IconColor; } }
[EditorBrowsable(EditorBrowsableState.Never)] [Browsable(false)] [DefaultValue(false)] public bool Hovered { get; set; }
[EditorBrowsable(EditorBrowsableState.Never)] [Browsable(false)] [DefaultValue(false)] public bool Clicked { get; set; }
public WindowsDefaultTitleBarButton() { }
protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); Hovered = true; }
protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); Hovered = false; }
protected override void OnMouseDown(MouseEventArgs mevent) { base.OnMouseDown(mevent); Clicked = true; }
protected override void OnMouseUp(MouseEventArgs mevent) { base.OnMouseUp(mevent); Clicked = false; }
protected override void OnClick(EventArgs e) { if (ButtonType == Type.Close) this.FindForm()?.Close(); else if (ButtonType == Type.Maximize) this.FindForm().WindowState = this.FindForm().WindowState == FormWindowState.Maximized ? FormWindowState.Normal : FormWindowState.Maximized; else this.FindForm().WindowState = FormWindowState.Minimized;
base.OnClick(e); }
protected override void OnPaint(PaintEventArgs pevent) { pevent.Graphics.FillRectangle(new SolidBrush(ActiveColor), pevent.ClipRectangle); pevent.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
if (ButtonType == Type.Close) drawCloseIcon(pevent); else if (ButtonType == Type.Maximize) drawMaximizeIcon(pevent); else drawMinimizeIcon(pevent); }
protected virtual void drawCloseIcon(PaintEventArgs e) { e.Graphics.DrawLine( new Pen(new SolidBrush(ActiveIconColor), 1.0f), e.ClipRectangle.X + e.ClipRectangle.Width / 2 - 5, e.ClipRectangle.Y + e.ClipRectangle.Height / 2 - 5, e.ClipRectangle.X + e.ClipRectangle.Width / 2 + 5, e.ClipRectangle.Y + e.ClipRectangle.Height / 2 + 5);
e.Graphics.DrawLine( new Pen(new SolidBrush(ActiveIconColor), 1.0f), e.ClipRectangle.X + e.ClipRectangle.Width / 2 - 5, e.ClipRectangle.Y + e.ClipRectangle.Height / 2 + 5, e.ClipRectangle.X + e.ClipRectangle.Width / 2 + 5, e.ClipRectangle.Y + e.ClipRectangle.Height / 2 - 5); ; }
protected virtual void drawMaximizeIcon(PaintEventArgs e) { if (this.FindForm().WindowState == FormWindowState.Normal) { e.Graphics.DrawRectangle( new Pen(new SolidBrush(ActiveIconColor), 1.0f), new Rectangle( e.ClipRectangle.X + e.ClipRectangle.Width / 2 - 5, e.ClipRectangle.Y + e.ClipRectangle.Height / 2 - 5, 10, 10)); } else if (this.FindForm().WindowState == FormWindowState.Maximized) { e.Graphics.DrawRectangle( new Pen(new SolidBrush(ActiveIconColor), 1.0f), new Rectangle( e.ClipRectangle.X + e.ClipRectangle.Width / 2 - 3, e.ClipRectangle.Y + e.ClipRectangle.Height / 2 - 5, 8, 8));
Rectangle rect = new Rectangle( e.ClipRectangle.X + e.ClipRectangle.Width / 2 - 5, e.ClipRectangle.Y + e.ClipRectangle.Height / 2 - 3, 8, 8);
e.Graphics.FillRectangle(new SolidBrush(this.ActiveColor), rect); e.Graphics.DrawRectangle(new Pen(new SolidBrush(this.ActiveIconColor), 1.0f), rect); } }
protected virtual void drawMinimizeIcon(PaintEventArgs e) { e.Graphics.DrawLine( new Pen(new SolidBrush(ActiveIconColor), 1.0f), e.ClipRectangle.X + e.ClipRectangle.Width / 2 - 5, e.ClipRectangle.Y + e.ClipRectangle.Height / 2, e.ClipRectangle.X + e.ClipRectangle.Width / 2 + 5, e.ClipRectangle.Y + e.ClipRectangle.Height / 2); } } |