yangyin
2025-02-24 b3b65a002fe68b1383314098790f5a153b87765f
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
#region Imports
 
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region SkyCheckBox
 
    [DefaultEvent("CheckedChanged")]
    public class SkyCheckBox : Control
    {
        #region " Control Help - MouseState & Flicker Control"
        private Point mouse = new(0, 0);
 
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            mouse = e.Location;
        }
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);
            Invalidate();
        }
 
        private bool _Checked;
        public bool Checked
        {
            get => _Checked;
            set
            {
                _Checked = value;
                CheckedChanged?.Invoke(this);
                Invalidate();
            }
        }
 
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            Height = 14;
        }
 
        protected override void OnClick(EventArgs e)
        {
            if (mouse.X <= Height - 1 || mouse.Y <= Width - 1)
            {
                Checked = !Checked;
                Invalidate();
            }
 
            base.OnClick(e);
        }
 
        public event CheckedChangedEventHandler CheckedChanged;
        public delegate void CheckedChangedEventHandler(object sender);
        #endregion
 
        #region Variables
        private SmoothingMode _SmoothingType = SmoothingMode.HighQuality;
        #endregion
 
        #region Settings
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        public Color BoxBGColorA { get; set; } = Color.FromArgb(245, 245, 245);
 
        public Color BoxBGColorB { get; set; } = Color.FromArgb(231, 231, 231);
 
        public Color BoxBorderColorA { get; set; } = Color.FromArgb(189, 189, 189);
 
        public Color BoxBorderColorB { get; set; } = Color.FromArgb(252, 252, 252);
 
        public Color BoxBorderColorC { get; set; } = Color.FromArgb(168, 168, 168);
 
        public Color CheckedColor { get; set; } = Color.FromArgb(220, 27, 94, 137);
        #endregion
 
        public SkyCheckBox() : base()
        {
            SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
            Font = new("Verdana", 6.75f, FontStyle.Bold);
            BackColor = Color.Transparent;
            ForeColor = Color.FromArgb(27, 94, 137);
            Size = new(90, 16);
            DoubleBuffered = true;
            Cursor = Cursors.Hand;
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
 
            Rectangle checkBoxRectangle = new(0, 0, Height - 1, Height - 1);
            G.SmoothingMode = SmoothingType;
 
            G.Clear(Parent.FindForm().BackColor);
 
            LinearGradientBrush bodyGrad = new(checkBoxRectangle, BoxBGColorA, BoxBGColorB, 90);
            G.FillRectangle(bodyGrad, bodyGrad.Rectangle);
            G.DrawRectangle(new(BoxBorderColorA), new Rectangle(0, 0, Height - 1, Height - 2));
            G.DrawRectangle(new(BoxBorderColorB), new Rectangle(1, 1, Height - 3, Height - 4));
            G.DrawLine(new(BoxBorderColorC), new Point(1, Height - 1), new Point(Height - 2, Height - 1));
 
            if (Checked)
            {
                Rectangle chkPoly = new(checkBoxRectangle.X + (checkBoxRectangle.Width / 4), checkBoxRectangle.Y + (checkBoxRectangle.Height / 4), checkBoxRectangle.Width / 2, checkBoxRectangle.Height / 2);
                Point[] Poly =
                {
                    new(chkPoly.X, chkPoly.Y + (chkPoly.Height / 2)),
                    new(chkPoly.X + (chkPoly.Width / 2), chkPoly.Y + chkPoly.Height),
                    new(chkPoly.X + chkPoly.Width, chkPoly.Y)
                };
                G.SmoothingMode = SmoothingType;
 
                G.DrawString("a", new Font("Marlett", 10.75f), new SolidBrush(CheckedColor), new Rectangle(-2, -1, Width - 1, Height - 1), new StringFormat
                {
                    Alignment = StringAlignment.Near,
                    LineAlignment = StringAlignment.Near
                });
            }
 
            G.DrawString(Text, Font, new SolidBrush(ForeColor), new Point(16, 0), new StringFormat
            {
                Alignment = StringAlignment.Near,
                LineAlignment = StringAlignment.Near
            });
 
            e.Graphics.DrawImage(B, 0, 0);
            G.Dispose();
            B.Dispose();
 
        }
    }
 
    #endregion
}