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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Util;
using DPumpHydr.WinFrmUI.RLT.Util.FoxBase;
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 FoxRadioButton
 
    [DefaultEvent("CheckedChanged")]
    public class FoxRadioButton : FoxBaseRadioButton
    {
        private Graphics G;
 
        public Color CheckedColor { get; set; } = FoxLibrary.ColorFromHex("#2C9CDA");
        public Color DisabledCheckedColor { get; set; } = FoxLibrary.ColorFromHex("#B6B4B4");
        public Color BorderColor { get; set; } = FoxLibrary.ColorFromHex("#C8C8C8");
        public Color DisabledBorderColor { get; set; } = FoxLibrary.ColorFromHex("#E6E6E6");
        public Color DisabledTextColor { get; set; } = FoxLibrary.ColorFromHex("#A6B2BE");
        public Color HoverBorderColor { get; set; } = FoxLibrary.ColorFromHex("#2C9CDA");
 
        public FoxRadioButton() : base()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
 
            Font = new("Segoe UI", 10);
            BackColor = Color.Transparent;
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            G = e.Graphics;
            G.SmoothingMode = SmoothingMode.HighQuality;
            G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
 
            //G.Clear(BackColor);
 
            if (Enabled)
            {
                switch (State)
                {
                    case FoxLibrary.MouseState.None:
                        using (Pen Border = new(BorderColor))
                        {
                            G.DrawEllipse(Border, new Rectangle(0, 0, 20, 20));
                        }
 
                        break;
                    default:
                        using (Pen Border = new(HoverBorderColor))
                        {
                            G.DrawEllipse(Border, new Rectangle(0, 0, 20, 20));
                        }
 
                        break;
                }
 
                using SolidBrush TextColor = new(ForeColor);
                G.DrawString(Text, Font, TextColor, new Point(27, 1));
            }
            else
            {
                using (Pen Border = new(DisabledBorderColor))
                {
                    G.DrawEllipse(Border, new Rectangle(0, 0, 20, 20));
                }
 
                using SolidBrush TextColor = new(DisabledTextColor);
                G.DrawString(Text, Font, TextColor, new Point(27, 1));
            }
 
            if (Checked)
            {
                if (Enabled)
                {
                    using SolidBrush FillColor = new(CheckedColor);
                    G.FillEllipse(FillColor, new Rectangle(4, 4, 12, 12));
                }
                else
                {
                    using SolidBrush FillColor = new(DisabledCheckedColor);
                    G.FillEllipse(FillColor, new Rectangle(4, 4, 12, 12));
                }
            }
 
            base.OnPaint(e);
        }
    }
 
    #endregion
}