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
#region Imports
 
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ParrotGroupBox
 
    public class ParrotGroupBox : System.Windows.Forms.GroupBox
    {
        public ParrotGroupBox()
        {
            Controls.Add(groupName);
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The color of the border")]
        public Color BorderColor
        {
            get => borderColor;
            set
            {
                borderColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The color of the text")]
        public Color TextColor
        {
            get => textColor;
            set
            {
                textColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The width of the border")]
        public int BorderWidth
        {
            get => borderWidth;
            set
            {
                borderWidth = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Show the text of the groupbox")]
        public bool ShowText
        {
            get => showText;
            set
            {
                showText = value;
                Invalidate();
            }
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            groupName.Visible = showText;
 
            if (showText)
            {
                groupName.BackColor = Color.Transparent;
 
                groupName.Text = Text;
                groupName.Font = Font;
                groupName.Location = new Point(9, 0);
                groupName.AutoSize = true;
                groupName.ForeColor = textColor;
 
                e.Graphics.DrawLine(new Pen(borderColor, borderWidth), 1, 6, 6, 6);
                e.Graphics.DrawLine(new Pen(borderColor, borderWidth), base.Width - 2, 6, groupName.Location.X + groupName.Width, 6);
                e.Graphics.DrawLine(new Pen(borderColor, borderWidth), 1, base.Height - 2, base.Width - 2, base.Height - 2);
                e.Graphics.DrawLine(new Pen(borderColor, borderWidth), 1, 6, 1, base.Height - 2);
                e.Graphics.DrawLine(new Pen(borderColor, borderWidth), base.Width - 2, 6, base.Width - 2, base.Height - 2);
            }
            else
            {
                e.Graphics.DrawLine(new Pen(borderColor, borderWidth), 1, 1, base.Width - 2, 1);
                e.Graphics.DrawLine(new Pen(borderColor, borderWidth), 1, base.Height - 2, base.Width - 2, base.Height - 2);
                e.Graphics.DrawLine(new Pen(borderColor, borderWidth), 1, 1, 1, base.Height - 2);
                e.Graphics.DrawLine(new Pen(borderColor, borderWidth), base.Width - 2, 1, base.Width - 2, base.Height - 2);
            }
        }
 
        private readonly Label groupName = new();
 
        private Color borderColor = Color.DodgerBlue;
 
        private Color textColor = Color.DodgerBlue;
 
        private int borderWidth = 1;
 
        private bool showText = true;
    }
 
    #endregion
}