yangyin
2025-03-27 b0de14c2670b9ff0079dacfb4b7457b438368f11
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#region Imports
 
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ParrotCheckBox
 
    public class ParrotCheckBox : Control
    {
        public ParrotCheckBox()
        {
            base.Size = new Size(100, 20);
            Text = base.Name;
            ForeColor = Color.White;
            currentColor = checkboxColor;
            Cursor = Cursors.Hand;
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Checked or unchecked")]
        public bool Checked
        {
            get => isChecked;
            set
            {
                isChecked = value;
                OnCheckedStateChanged();
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Thickness of the tick when checked")]
        public int TickThickness
        {
            get => tickThickness;
            set
            {
                tickThickness = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Checkbox color")]
        public Color CheckboxColor
        {
            get => checkboxColor;
            set
            {
                checkboxColor = value;
                currentColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Checkbox color")]
        public Color CheckboxCheckColor
        {
            get => checkboxCheckColor;
            set
            {
                checkboxCheckColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Checkbox ios border color")]
        public Color BorderColor
        {
            get => borderColor;
            set
            {
                borderColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Checkbox ios badge color")]
        public Color BadgeColor
        {
            get => badgeColor;
            set
            {
                badgeColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Checkbox color when hovering")]
        public Color CheckboxHoverColor
        {
            get => checkboxHoverColor;
            set
            {
                checkboxHoverColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The Checkbox style")]
        public Style CheckboxStyle
        {
            get => checkboxStyle;
            set
            {
                checkboxStyle = value;
                Invalidate();
            }
        }
 
        private SmoothingMode _SmoothingType = SmoothingMode.AntiAlias;
        [Category("Parrot")]
        [Browsable(true)]
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        private PixelOffsetMode _PixelOffsetType = PixelOffsetMode.HighQuality;
        [Category("Parrot")]
        [Browsable(true)]
        public PixelOffsetMode PixelOffsetType
        {
            get => _PixelOffsetType;
            set
            {
                _PixelOffsetType = value;
                Invalidate();
            }
        }
 
        private TextRenderingHint _TextRenderingType = TextRenderingHint.ClearTypeGridFit;
        [Category("Parrot")]
        [Browsable(true)]
        public TextRenderingHint TextRenderingType
        {
            get => _TextRenderingType;
            set
            {
                _TextRenderingType = value;
                Invalidate();
            }
        }
 
        public event EventHandler CheckedStateChanged;
 
        protected virtual void OnCheckedStateChanged()
        {
            CheckedStateChanged?.Invoke(this, new EventArgs());
        }
 
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);
            currentColor = checkboxHoverColor;
            Invalidate();
        }
 
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            currentColor = checkboxColor;
            Invalidate();
        }
 
        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);
            if (!Checked)
            {
                Checked = true;
                return;
            }
            Checked = false;
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingType;
            if (checkboxStyle == Style.Material)
            {
                e.Graphics.FillRectangle(new SolidBrush(currentColor), 1, 1, base.Height - 2, base.Height - 2);
                if (isChecked)
                {
                    e.Graphics.DrawLine(new Pen(checkboxCheckColor, tickThickness), 2, base.Height / 3 * 2, base.Height / 2, base.Height - 2);
                    e.Graphics.DrawLine(new Pen(checkboxCheckColor, tickThickness), base.Height / 2, base.Height - 2, base.Height - 2, 1);
                }
            }
            if (checkboxStyle == Style.iOS)
            {
                if (!isChecked)
                {
                    e.Graphics.DrawEllipse(new Pen(BorderColor), 2, 2, base.Height - 4, base.Height - 4);
                }
                if (isChecked)
                {
                    e.Graphics.FillEllipse(new SolidBrush(BadgeColor), 1, 1, base.Height - 2, base.Height - 2);
                    e.Graphics.DrawLine(new Pen(checkboxCheckColor, tickThickness), base.Height / 5, base.Height / 2, base.Height / 2, base.Height / 4 * 3);
                    e.Graphics.DrawLine(new Pen(checkboxCheckColor, tickThickness), base.Height / 2, base.Height / 4 * 3, base.Height / 5 * 4, base.Height / 4);
                }
            }
            StringFormat stringFormat = new()
            {
                LineAlignment = StringAlignment.Center,
                Alignment = StringAlignment.Near
            };
            SolidBrush brush = new(ForeColor);
            RectangleF layoutRectangle = new(base.Height + 3, 0f, base.Width - base.Height - 2, Height);
            e.Graphics.PixelOffsetMode = PixelOffsetType;
            e.Graphics.TextRenderingHint = TextRenderingType;
            e.Graphics.DrawString(Text, Font, brush, layoutRectangle, stringFormat);
            base.OnPaint(e);
        }
 
        private bool isChecked;
 
        private int tickThickness = 2;
 
        private Color checkboxColor = Color.FromArgb(0, 162, 250);
 
        private Color checkboxCheckColor = Color.White;
 
        private Color checkboxHoverColor = Color.FromArgb(249, 55, 98);
 
        private Style checkboxStyle = Style.Material;
 
        private Color currentColor;
 
        private Color borderColor = Color.FromArgb(200, 200, 200);
 
        private Color badgeColor = Color.FromArgb(0, 120, 255);
 
        public enum Style
        {
            iOS,
            Material
        }
    }
 
    #endregion
}