tangxu
2024-11-04 ebd031e3bed6c1cfddce8fc9b98f7f9e95fb9e32
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
#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 MoonRadioButton
 
    [DefaultEvent("CheckedChanged")]
    public class MoonRadioButton : MoonControl
    {
        private Color BG;
        private Color FC;
 
        private bool _Checked;
        public bool Checked
        {
            get => _Checked;
            set
            {
                _Checked = value;
                InvalidateControls();
                CheckedChanged?.Invoke(this);
                Invalidate();
            }
        }
 
        private Color _CheckedColor = Color.Gray;
        public Color CheckedColor
        {
            get => _CheckedColor;
            set
            {
                _CheckedColor = value;
                Invalidate();
            }
        }
 
        private Color _HoverColor = Color.White;
        public Color HoverColor
        {
            get => _HoverColor;
            set
            {
                _HoverColor = value;
                Invalidate();
            }
        }
 
        private Color _HoverBackColor = Color.Gray;
        public Color HoverBackColor
        {
            get => _HoverBackColor;
            set
            {
                _HoverBackColor = value;
                Invalidate();
            }
        }
 
        private Color _CircleColorA = Color.White;
        public Color CircleColorA
        {
            get => _CircleColorA;
            set
            {
                _CircleColorA = value;
                Invalidate();
            }
        }
 
        private Color _CircleColorB = Color.LightGray;
        public Color CircleColorB
        {
            get => _CircleColorB;
            set
            {
                _CircleColorB = value;
                Invalidate();
            }
        }
 
        private Color _CircleColorC = Color.LightGray;
        public Color CircleColorC
        {
            get => _CircleColorC;
            set
            {
                _CircleColorC = value;
                Invalidate();
            }
        }
 
        private SmoothingMode _SmoothingType = SmoothingMode.HighQuality;
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        public event CheckedChangedEventHandler CheckedChanged;
        public delegate void CheckedChangedEventHandler(object sender);
 
        private void InvalidateControls()
        {
            if (!IsHandleCreated || !_Checked)
            {
                return;
            }
 
            foreach (Control C in Parent.Controls)
            {
                if (!object.ReferenceEquals(C, this) && C is MoonRadioButton button)
                {
                    button.Checked = false;
                }
            }
        }
 
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!_Checked)
            {
                Checked = true;
            }
 
            base.OnMouseDown(e);
        }
 
        public MoonRadioButton()
        {
            LockHeight = 22;
            Width = 130;
            SetColor("BG", Color.FromArgb(240, 240, 240));
            SetColor("FC", Color.Gray);
            Cursor = Cursors.Hand;
            Font = new("Segoe UI", 9);
        }
 
        protected override void ColorHook()
        {
            BG = GetColor("BG");
            FC = GetColor("FC");
        }
 
        protected override void PaintHook()
        {
            G.Clear(BG);
 
            G.SmoothingMode = SmoothingType;
 
            if (_Checked)
            {
                G.FillEllipse(new SolidBrush(CheckedColor), new Rectangle(new Point(7, 7), new Size(8, 8)));
            }
 
            if (State == MouseStateMoon.Over)
            {
                G.FillEllipse(new SolidBrush(HoverColor), new Rectangle(new Point(4, 4), new Size(14, 14)));
                if (_Checked)
                {
                    G.FillEllipse(new SolidBrush(HoverBackColor), new Rectangle(new Point(7, 7), new Size(8, 8)));
                }
            }
 
            G.DrawEllipse(new(new SolidBrush(CircleColorA)), new Rectangle(new Point(3, 3), new Size(16, 16)));
            G.DrawEllipse(new(new SolidBrush(CircleColorB)), new Rectangle(new Point(2, 2), new Size(18, 18)));
            G.DrawEllipse(new(new SolidBrush(CircleColorC)), new Rectangle(new Point(4, 4), new Size(14, 14)));
 
            G.DrawString(Text, Font, new SolidBrush(FC), 23, 3);
        }
    }
 
    #endregion
}