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
153
154
155
156
157
158
159
160
161
162
163
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Util;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region AirRadioButton
 
    [DefaultEventAttribute("CheckedChanged")]
    public class AirRadioButton : AirControl
    {
        public AirRadioButton()
        {
            Font = new("Segoe UI", 9);
            LockHeight = 17;
            SetColor("Text", 60, 60, 60);
            SetColor("Gradient top", 237, 237, 237);
            SetColor("Gradient bottom", 230, 230, 230);
            SetColor("Borders", 167, 167, 167);
            SetColor("Bullet", 100, 100, 100);
            Width = 110;
            Cursor = Cursors.Hand;
        }
 
        private int X;
        private Color TextColor, G1, G2, Bo, Bb;
 
        protected override void ColorHook()
        {
            TextColor = GetColor("Text");
            G1 = GetColor("Gradient top");
            G2 = GetColor("Gradient bottom");
            Bb = GetColor("Bullet");
            Bo = GetColor("Borders");
        }
 
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            X = e.Location.X;
            Invalidate();
        }
 
        protected override void PaintHook()
        {
            G.Clear(BackColor);
            G.SmoothingMode = SmoothingMode.HighQuality;
            if (_Checked)
            {
                LinearGradientBrush LGB = new(new Rectangle(new Point(0, 0), new Size(14, 14)), G1, G2, 90f);
                G.FillEllipse(LGB, new Rectangle(new Point(0, 0), new Size(14, 14)));
            }
            else
            {
                LinearGradientBrush LGB = new(new Rectangle(new Point(0, 0), new Size(14, 16)), G1, G2, 90f);
                G.FillEllipse(LGB, new Rectangle(new Point(0, 0), new Size(14, 14)));
            }
 
            if (State == MouseStateAir.Over & X < 15)
            {
                SolidBrush SB = new(Color.FromArgb(10, Color.Black));
                G.FillEllipse(SB, new Rectangle(new Point(0, 0), new Size(14, 14)));
            }
            else if (State == MouseStateAir.Down & X < 15)
            {
                SolidBrush SB = new(Color.FromArgb(20, Color.Black));
                G.FillEllipse(SB, new Rectangle(new Point(0, 0), new Size(14, 14)));
            }
 
            GraphicsPath P = new();
            P.AddEllipse(new Rectangle(0, 0, 14, 14));
            G.SetClip(P);
 
            LinearGradientBrush LLGGBB = new(new Rectangle(0, 0, 14, 5), Color.FromArgb(150, Color.White), Color.Transparent, 90f);
            G.FillRectangle(LLGGBB, LLGGBB.Rectangle);
 
            G.ResetClip();
 
            G.DrawEllipse(new(Bo), new Rectangle(new Point(0, 0), new Size(14, 14)));
 
            if (_Checked)
            {
                SolidBrush LGB = new(Bb);
                G.FillEllipse(LGB, new Rectangle(new Point(4, 4), new Size(6, 6)));
            }
 
            DrawText(new SolidBrush(TextColor), HorizontalAlignment.Left, 17, -2);
        }
 
        private int _Field = 16;
        public int Field
        {
            get => _Field;
            set
            {
                if (value < 4)
                {
                    return;
                }
 
                _Field = value;
                LockHeight = value;
                Invalidate();
            }
        }
 
        private bool _Checked;
        public bool Checked
        {
            get => _Checked;
            set
            {
                _Checked = value;
                InvalidateControls();
                CheckedChanged?.Invoke(this);
                Invalidate();
            }
        }
 
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!_Checked)
            {
                Checked = true;
            }
 
            base.OnMouseDown(e);
        }
 
        public event CheckedChangedEventHandler CheckedChanged;
        public delegate void CheckedChangedEventHandler(object sender);
 
        protected override void OnCreation()
        {
            InvalidateControls();
        }
 
        private void InvalidateControls()
        {
            if (!IsHandleCreated || !_Checked)
            {
                return;
            }
 
            foreach (Control C in Parent.Controls)
            {
                if (!object.ReferenceEquals(C, this) && C is AirRadioButton button)
                {
                    button.Checked = false;
                }
            }
        }
 
    }
 
    #endregion
}