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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Util;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ThunderRadioButton
 
    [DefaultEvent("CheckedChanged")]
    public class ThunderRadioButton : Control
    {
        private MouseStateThunder State = MouseStateThunder.None;
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            State = MouseStateThunder.Down;
            Invalidate();
        }
 
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            State = MouseStateThunder.Over;
            Invalidate();
        }
 
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);
            State = MouseStateThunder.Over;
            Invalidate();
        }
 
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            State = MouseStateThunder.None;
            Invalidate();
        }
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            Height = 16;
        }
 
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);
            Invalidate();
        }
 
        protected override void OnClick(EventArgs e)
        {
            Checked = !Checked;
            base.OnClick(e);
        }
 
        private bool _Checked = false;
        public bool Checked
        {
            get => _Checked;
            set
            {
                _Checked = value;
                InvalidateControls();
                CheckedChanged?.Invoke(this, EventArgs.Empty);
                Invalidate();
            }
        }
        protected override void OnCreateControl()
        {
            base.OnCreateControl();
            InvalidateControls();
        }
 
        private void InvalidateControls()
        {
            if (!IsHandleCreated || !_Checked)
            {
                return;
            }
 
            foreach (Control C in Parent.Controls)
            {
                if (C is ThunderRadioButton button && C != this)
                {
                    button.Checked = false;
                }
            }
        }
 
        public ThunderRadioButton()
        {
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.UserPaint, true);
            BackColor = Color.Transparent;
            ForeColor = Color.WhiteSmoke;
            Size = new(160, 16);
            DoubleBuffered = true;
            Cursor = Cursors.Hand;
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
            G.Clear(BackColor);
            Rectangle radioBtnRectangle = new(0, 0, Height - 1, Height - 1);
            Rectangle R1 = new(4, 4, Height - 9, Height - 9);
            StringFormat format = new() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near };
            LinearGradientBrush bgGrad = new(radioBtnRectangle, Color.FromArgb(174, 195, 30), Color.FromArgb(141, 153, 16), 90);
            Color C1 = Color.FromArgb(250, 15, 15, 15);
            SolidBrush nb = new(ForeColor);
            G.SmoothingMode = SmoothingMode.HighQuality;
            G.CompositingQuality = CompositingQuality.HighQuality;
            Font drawFont = new("Tahoma", 10, FontStyle.Bold);
 
            G.FillEllipse(bgGrad, radioBtnRectangle);
            G.DrawEllipse(new(Color.Black), radioBtnRectangle);
 
            if (Checked)
            {
                LinearGradientBrush chkGrad = new(R1, C1, C1, 90);
                G.FillEllipse(chkGrad, R1);
            }
 
            G.DrawString(Text, drawFont, Brushes.Black, new Point(17, 2), format);
            G.DrawString(Text, drawFont, nb, new Point(16, 1), format);
 
            e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
            G.Dispose();
            B.Dispose();
        }
 
        public event EventHandler CheckedChanged;
    }
 
    #endregion
}