tangxu
2024-12-24 91105b77c916d06dd30380e20594e29f85eae3da
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
#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 RibbonRadioButton
 
    [DefaultEvent("CheckedChanged")]
    public class RibbonRadioButton : Control
    {
        #region " Control Help - MouseState & Flicker Control"
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            Height = 16;
        }
 
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);
            Invalidate();
        }
 
        private bool _Checked;
        public bool Checked
        {
            get => _Checked;
            set
            {
                _Checked = value;
                InvalidateControls();
                CheckedChanged?.Invoke(this);
                Invalidate();
            }
        }
 
        protected override void OnClick(EventArgs e)
        {
            if (!_Checked)
            {
                @Checked = true;
            }
            else
            {
                @Checked = false;
            }
 
            base.OnClick(e);
        }
 
        public event CheckedChangedEventHandler CheckedChanged;
        public delegate void CheckedChangedEventHandler(object sender);
        protected override void OnCreateControl()
        {
            base.OnCreateControl();
            InvalidateControls();
        }
 
        private void InvalidateControls()
        {
            if (!IsHandleCreated || !_Checked)
            {
                return;
            }
 
            foreach (Control C in Parent.Controls)
            {
                if (!object.ReferenceEquals(C, this) && C is RibbonRadioButton button)
                {
                    button.Checked = false;
                }
            }
        }
 
        private SmoothingMode _SmoothingType = SmoothingMode.HighQuality;
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        private CompositingQuality _CompositingQualityType = CompositingQuality.HighQuality;
        public CompositingQuality CompositingQualityType
        {
            get => _CompositingQualityType;
            set
            {
                _CompositingQualityType = value;
                Invalidate();
            }
        }
 
        private TextRenderingHint _TextRenderingType = TextRenderingHint.AntiAliasGridFit;
        public TextRenderingHint TextRenderingType
        {
            get => _TextRenderingType;
            set
            {
                _TextRenderingType = value;
                Invalidate();
            }
        }
 
        private Color _CheckedColor = Color.FromArgb(40, 40, 40);
        public Color CheckedColor
        {
            get => _CheckedColor;
            set
            {
                _CheckedColor = value;
                Invalidate();
            }
        }
 
        private Color _CircleBorderColor = Color.FromArgb(117, 120, 117);
        public Color CircleBorderColor
        {
            get => _CircleBorderColor;
            set
            {
                _CircleBorderColor = value;
                Invalidate();
            }
        }
 
        private Color _CircleEdgeColor = Color.WhiteSmoke;
        public Color CircleEdgeColor
        {
            get => _CircleEdgeColor;
            set
            {
                _CircleEdgeColor = value;
                Invalidate();
            }
        }
 
        private Color _CheckedBorderColorA = Color.FromArgb(203, 201, 205);
        public Color CheckedBorderColorA
        {
            get => _CheckedBorderColorA;
            set
            {
                _CheckedBorderColorA = value;
                Invalidate();
            }
        }
 
        private Color _CheckedBorderColorB = Color.FromArgb(188, 186, 190);
        public Color CheckedBorderColorB
        {
            get => _CheckedBorderColorB;
            set
            {
                _CheckedBorderColorB = value;
                Invalidate();
            }
        }
        #endregion
 
        public RibbonRadioButton() : base()
        {
            SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
            BackColor = Color.Transparent;
            ForeColor = Color.FromArgb(40, 40, 40);
            Size = new(133, 16);
            DoubleBuffered = true;
            Cursor = Cursors.Hand;
            Font = new("Tahoma", 8, FontStyle.Bold);
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
            Rectangle radioBtnRectangle = new(0, 0, Height, Height - 1);
            Rectangle Inner = new(1, 1, Height - 2, Height - 3);
 
            G.SmoothingMode = SmoothingType;
            G.CompositingQuality = CompositingQualityType;
            G.TextRenderingHint = TextRenderingType;
 
            G.Clear(BackColor);
 
            LinearGradientBrush bgGrad = new(radioBtnRectangle, CheckedBorderColorA, CheckedBorderColorB, 90F);
            G.FillEllipse(bgGrad, radioBtnRectangle);
 
            G.DrawEllipse(new(CircleBorderColor), radioBtnRectangle);
            G.DrawEllipse(new(CircleEdgeColor), Inner);
 
            if (Checked)
            {
                G.DrawString("n", new Font("Marlett", 8, FontStyle.Bold), new SolidBrush(CheckedColor), 0, 3);
            }
 
            G.DrawString(Text, Font, new SolidBrush(ForeColor), new Point(18, 8), new StringFormat
            {
                Alignment = StringAlignment.Near,
                LineAlignment = StringAlignment.Center
            });
 
            e.Graphics.DrawImage(B, 0, 0);
            G.Dispose();
            B.Dispose();
        }
    }
 
    #endregion
}