-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRJToggleButton.cs
164 lines (143 loc) · 4.27 KB
/
RJToggleButton.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
namespace DHCPClient
{
class RJToggleButton : CheckBox
{
//Fields
private Color onBackColor = Color.MediumSlateBlue;
private Color onToggleColor = Color.WhiteSmoke;
private Color offBackColor = Color.Gray;
private Color offToggleColor = Color.Gainsboro;
private bool solidStyle = true;
//Properties
[Category("RJ Code Advance")]
public Color OnBackColor
{
get
{
return onBackColor;
}
set
{
onBackColor = value;
this.Invalidate();
}
}
[Category("RJ Code Advance")]
public Color OnToggleColor
{
get
{
return onToggleColor;
}
set
{
onToggleColor = value;
this.Invalidate();
}
}
[Category("RJ Code Advance")]
public Color OffBackColor
{
get
{
return offBackColor;
}
set
{
offBackColor = value;
this.Invalidate();
}
}
[Category("RJ Code Advance")]
public Color OffToggleColor
{
get
{
return offToggleColor;
}
set
{
offToggleColor = value;
this.Invalidate();
}
}
[Browsable(false)]
public override string Text
{
get
{
return base.Text;
}
set
{
}
}
[Category("RJ Code Advance")]
[DefaultValue(true)]
public bool SolidStyle
{
get
{
return solidStyle;
}
set
{
solidStyle = value;
this.Invalidate();
}
}
//Constructor
public RJToggleButton()
{
this.MinimumSize = new Size(45, 22);
}
//Methods
private GraphicsPath GetFigurePath()
{
int arcSize = this.Height - 1;
Rectangle leftArc = new Rectangle(0, 0, arcSize, arcSize);
Rectangle rightArc = new Rectangle(this.Width - arcSize - 2, 0, arcSize, arcSize);
GraphicsPath path = new GraphicsPath();
path.StartFigure();
path.AddArc(leftArc, 90, 180);
path.AddArc(rightArc, 270, 180);
path.CloseFigure();
return path;
}
protected override void OnPaint(PaintEventArgs pevent)
{
int toggleSize = this.Height - 5;
pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
pevent.Graphics.Clear(this.Parent.BackColor);
if (this.Checked) //ON
{
//Draw the control surface
if (solidStyle)
pevent.Graphics.FillPath(new SolidBrush(onBackColor), GetFigurePath());
else pevent.Graphics.DrawPath(new Pen(onBackColor, 2), GetFigurePath());
//Draw the toggle
pevent.Graphics.FillEllipse(new SolidBrush(onToggleColor),
new Rectangle(this.Width - this.Height + 1, 2, toggleSize, toggleSize));
}
else //OFF
{
//Draw the control surface
if (solidStyle)
pevent.Graphics.FillPath(new SolidBrush(offBackColor), GetFigurePath());
else pevent.Graphics.DrawPath(new Pen(offBackColor, 2), GetFigurePath());
//Draw the toggle
pevent.Graphics.FillEllipse(new SolidBrush(offToggleColor),
new Rectangle(2, 2, toggleSize, toggleSize));
}
}
}
}