-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathMyButton.cs
More file actions
200 lines (156 loc) · 7.09 KB
/
MyButton.cs
File metadata and controls
200 lines (156 loc) · 7.09 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace MissionPlanner.Controls
{
public class MyButton : Button
{
bool _mouseover = false;
bool _mousedown = false;
internal Color _BGGradTop;
internal Color _BGGradBot;
internal Color _TextColor;
internal Color _TextColorNotEnabled;
internal Color _Outline;
internal Color _ColorNotEnabled;
internal Color _ColorMouseOver;
internal Color _ColorMouseDown;
bool inOnPaint = false;
[System.ComponentModel.Browsable(true), System.ComponentModel.Category("Colors")]
[DefaultValue(typeof(Color), "0x94, 0xc1, 0x1f")]
public Color BGGradTop { get { return _BGGradTop; } set { _BGGradTop = value; this.Invalidate(); } }
[System.ComponentModel.Browsable(true), System.ComponentModel.Category("Colors")]
[DefaultValue(typeof(Color), "0xcd, 0xe2, 0x96")]
public Color BGGradBot { get { return _BGGradBot; } set { _BGGradBot = value; this.Invalidate(); } }
[System.ComponentModel.Browsable(true), System.ComponentModel.Category("Colors")]
[DefaultValue(typeof(Color), "73, 0x2b, 0x3a, 0x03")]
public Color ColorNotEnabled { get { return _ColorNotEnabled; } set { _ColorNotEnabled = value; this.Invalidate(); } }
[System.ComponentModel.Browsable(true), System.ComponentModel.Category("Colors")]
[DefaultValue(typeof(Color), "73, 0x2b, 0x3a, 0x03")]
public Color ColorMouseOver { get { return _ColorMouseOver; } set { _ColorMouseOver = value; this.Invalidate(); } }
[System.ComponentModel.Browsable(true), System.ComponentModel.Category("Colors")]
[DefaultValue(typeof(Color), "150, 0x2b, 0x3a, 0x03")]
public Color ColorMouseDown { get { return _ColorMouseDown; } set { _ColorMouseDown = value; this.Invalidate(); } }
// i want to ignore forecolor
[System.ComponentModel.Browsable(true), System.ComponentModel.Category("Colors")]
[DefaultValue(typeof(Color), "0x40, 0x57, 0x04")]
public Color TextColor { get { return _TextColor; } set { _TextColor = value; this.Invalidate(); } }
[System.ComponentModel.Browsable(true), System.ComponentModel.Category("Colors")]
[DefaultValue(typeof(Color), "0x40, 0x57, 0x04")]
public Color TextColorNotEnabled { get { return (_TextColorNotEnabled.IsEmpty) ? _TextColor : _TextColorNotEnabled; } set { _TextColorNotEnabled = value; this.Invalidate(); } }
[System.ComponentModel.Browsable(true), System.ComponentModel.Category("Colors")]
[DefaultValue(typeof(Color), "0x79, 0x94, 0x29")]
public Color Outline { get { return _Outline; } set { _Outline = value; this.Invalidate(); } }
protected override Size DefaultSize => base.DefaultSize;
public MyButton()
{
_BGGradTop = Color.FromArgb(0x94, 0xc1, 0x1f);
_BGGradBot = Color.FromArgb(0xcd, 0xe2, 0x96);
_TextColor = Color.FromArgb(0x40, 0x57, 0x04);
_Outline = Color.FromArgb(0x79, 0x94, 0x29);
_ColorNotEnabled = Color.FromArgb(73, 0x2b, 0x3a, 0x03);
_ColorMouseOver = Color.FromArgb(73, 0x2b, 0x3a, 0x03);
_ColorMouseDown = Color.FromArgb(150, 0x2b, 0x3a, 0x03);
}
protected override void OnPaint(PaintEventArgs pevent)
{
//base.OnPaint(pevent);
if (inOnPaint)
return;
inOnPaint = true;
try
{
Graphics gr = pevent.Graphics;
gr.Clear(this.BackColor);
gr.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle outside = new Rectangle(0, 0, this.Width, this.Height);
LinearGradientBrush linear = new LinearGradientBrush(outside, BGGradTop, BGGradBot, LinearGradientMode.Vertical);
Pen mypen = new Pen(Outline, 1);
GraphicsPath outline = new GraphicsPath();
float wid = this.Height / 3f;
wid = 1;
int width = this.Width - 1;
int height = this.Height - 1;
// tl
outline.AddArc(0, 0, wid, wid, 180, 90);
// top line
outline.AddLine(wid, 0, width - wid, 0);
// tr
outline.AddArc(width - wid, 0, wid, wid, 270, 90);
// br
outline.AddArc(width - wid, height - wid, wid, wid, 0, 90);
// bottom line
outline.AddLine(wid, height, width - wid, height);
// bl
outline.AddArc(0, height - wid, wid, wid, 90, 90);
// left line
outline.AddLine(0, height - wid, 0, wid - wid / 2);
gr.FillPath(linear, outline);
gr.DrawPath(mypen, outline);
SolidBrush mybrush = this.Enabled ? new SolidBrush(TextColor) : new SolidBrush(TextColorNotEnabled);
if (_mouseover)
{
SolidBrush brush = new SolidBrush(ColorMouseOver);
gr.FillPath(brush, outline);
}
if (_mousedown)
{
SolidBrush brush = new SolidBrush(ColorMouseDown);
gr.FillPath(brush, outline);
}
if (!this.Enabled)
{
SolidBrush brush = new SolidBrush(_ColorNotEnabled);
gr.FillPath(brush, outline);
}
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
string display = this.Text;
int amppos = display.IndexOf('&');
if (amppos != -1)
display = display.Remove(amppos, 1);
gr.DrawString(display, this.Font, mybrush, outside, stringFormat);
}
catch { }
inOnPaint = false;
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
//base.OnPaintBackground(pevent);
}
protected override void OnMouseEnter(EventArgs e)
{
_mouseover = true;
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
_mouseover = false;
base.OnMouseLeave(e);
}
protected override void OnMouseDown(MouseEventArgs mevent)
{
_mousedown = true;
base.OnMouseDown(mevent);
}
protected override void OnMouseUp(MouseEventArgs mevent)
{
_mousedown = false;
base.OnMouseUp(mevent);
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
}
}
}