yangyin
2025-03-27 b0de14c2670b9ff0079dacfb4b7457b438368f11
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
#region Imports
 
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region DungeonCheckBox
 
    [DefaultEvent("CheckedChanged")]
    public class DungeonCheckBox : Control
    {
        #region Variables
 
        private GraphicsPath Shape;
        private LinearGradientBrush GB;
        private Rectangle R1;
        private Rectangle R2;
        private bool _Checked;
 
        public event CheckedChangedEventHandler CheckedChanged;
        public delegate void CheckedChangedEventHandler(object sender);
 
        #endregion
 
        #region Properties
 
        public bool Checked
        {
            get => _Checked;
            set
            {
                _Checked = value;
                CheckedChanged?.Invoke(this);
                Invalidate();
            }
        }
 
        public Color CheckedColor { get; set; } = Color.FromArgb(255, 255, 255);
 
        public Color CheckedBackColorA { get; set; } = Color.FromArgb(213, 85, 32);
 
        public Color CheckedBackColorB { get; set; } = Color.FromArgb(224, 123, 82);
 
        public Color CheckedBorderColor { get; set; } = Color.FromArgb(182, 88, 55);
 
        #endregion
 
        public DungeonCheckBox()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
 
            BackColor = Color.Transparent;
            DoubleBuffered = true;
            // Reduce control flicker
            Font = new("Segoe UI", 12);
            Size = new(160, 26);
            ForeColor = Color.FromArgb(76, 76, 95);
            Cursor = Cursors.Hand;
        }
 
        protected override void OnClick(EventArgs e)
        {
            _Checked = !_Checked;
            CheckedChanged?.Invoke(this);
            Focus();
            Invalidate();
            base.OnClick(e);
        }
 
        protected override void OnTextChanged(EventArgs e)
        {
            Invalidate();
            base.OnTextChanged(e);
        }
 
        protected override void OnResize(EventArgs e)
        {
            if (Width > 0 && Height > 0)
            {
                Shape = new();
 
                R1 = new(17, 0, Width, Height + 1);
                R2 = new(0, 0, Width, Height);
                GB = new(new Rectangle(0, 0, 25, 25), CheckedBackColorA, CheckedBackColorB, 90);
 
                GraphicsPath MyDrawer = Shape;
                MyDrawer.AddArc(0, 0, 7, 7, 180, 90);
                MyDrawer.AddArc(7, 0, 7, 7, -90, 90);
                MyDrawer.AddArc(7, 7, 7, 7, 0, 90);
                MyDrawer.AddArc(0, 7, 7, 7, 90, 90);
                MyDrawer.CloseAllFigures();
                Height = 15;
            }
 
            Invalidate();
            base.OnResize(e);
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
 
            Graphics MyDrawer = e.Graphics;
            //MyDrawer.Clear(BackColor);
            MyDrawer.SmoothingMode = SmoothingMode.AntiAlias;
 
            MyDrawer.FillPath(GB, Shape);
            // Fill the body of the CheckBox
            MyDrawer.DrawPath(new(CheckedBorderColor), Shape);
            // Draw the border
 
            MyDrawer.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(17, 0, Width, Height - 1), new StringFormat { LineAlignment = StringAlignment.Center });
 
            if (Checked)
            {
                MyDrawer.DrawString("ü", new Font("Wingdings", 12), new SolidBrush(CheckedColor), new Rectangle(-2, 1, Width, Height + 2), new StringFormat { LineAlignment = StringAlignment.Center });
            }
 
            e.Dispose();
        }
    }
 
    #endregion
}