tangxu
2025-02-10 e40718947b5aa9205c87a7478aa86c37a82e0510
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
#region Imports
 
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region SkyTextBox
 
    public class SkyTextBox : Control
    {
        private readonly TextBox txtbox = new();
 
        #region " Control Help - Properties & Flicker Control "
 
        private bool _passmask = false;
        public bool UseSystemPasswordChar
        {
            get => _passmask;
            set
            {
                txtbox.UseSystemPasswordChar = UseSystemPasswordChar;
                _passmask = value;
                Invalidate();
            }
        }
 
        private int _maxchars = 32767;
        public int MaxLength
        {
            get => _maxchars;
            set
            {
                _maxchars = value;
                txtbox.MaxLength = MaxLength;
                Invalidate();
            }
        }
 
        private HorizontalAlignment _align;
        public HorizontalAlignment TextAlignment
        {
            get => _align;
            set
            {
                _align = value;
                Invalidate();
            }
        }
 
        private bool _multiline = false;
        public bool MultiLine
        {
            get => _multiline;
            set
            {
                _multiline = value;
                Invalidate();
            }
        }
 
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);
            Invalidate();
        }
 
        protected override void OnBackColorChanged(EventArgs e)
        {
            base.OnBackColorChanged(e);
            txtbox.BackColor = BackColor;
            Invalidate();
        }
 
        protected override void OnForeColorChanged(EventArgs e)
        {
            base.OnForeColorChanged(e);
            txtbox.ForeColor = ForeColor;
            Invalidate();
        }
 
        protected override void OnFontChanged(EventArgs e)
        {
            base.OnFontChanged(e);
            txtbox.Font = Font;
        }
 
        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
            txtbox.Focus();
        }
 
        public void TextChngTxtBox(object system, EventArgs e)
        {
            Text = txtbox.Text;
        }
 
        public void TextChng(object system, EventArgs e)
        {
            txtbox.Text = Text;
        }
 
        public void NewTextBox()
        {
            {
                txtbox.Multiline = false;
                txtbox.BackColor = UnknownBackColor;
                txtbox.ForeColor = ForeColor;
                txtbox.Text = string.Empty;
                txtbox.TextAlign = HorizontalAlignment.Center;
                txtbox.BorderStyle = BorderStyle.None;
                txtbox.Location = new(5, 4);
                txtbox.Font = new("Trebuchet MS", 8.25f, FontStyle.Bold);
                txtbox.Size = new(Width - 10, Height - 11);
                txtbox.UseSystemPasswordChar = UseSystemPasswordChar;
            }
 
        }
        #endregion
 
        #region Variables
        private SmoothingMode _SmoothingType = SmoothingMode.HighQuality;
        #endregion
 
        #region Settings
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        public Color BorderColorA { get; set; } = Color.FromArgb(220, 220, 220);
 
        public Color BorderColorB { get; set; } = Color.FromArgb(228, 228, 228);
 
        public Color BorderColorC { get; set; } = Color.FromArgb(191, 191, 191);
 
        public Color BorderColorD { get; set; } = Color.FromArgb(254, 254, 254);
 
        public Color BaseColor { get; set; } = Color.Transparent;
 
        public Color UnknownBackColor { get; set; } = Color.FromArgb(43, 43, 43);
        #endregion
 
        public SkyTextBox() : base()
        {
            NewTextBox();
            Controls.Add(txtbox);
 
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
 
            Text = "";
            BackColor = Color.FromArgb(233, 233, 233);
            ForeColor = Color.FromArgb(27, 94, 137);
            Font = new("Verdana", 6.75f, FontStyle.Bold);
            Size = new(75, 35);
            DoubleBuffered = true;
            txtbox.TextChanged += new EventHandler(TextChngTxtBox);
            base.TextChanged += new EventHandler(TextChng);
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
            G.SmoothingMode = SmoothingType;
 
            Height = txtbox.Height + 10;
            {
                txtbox.Width = Width - 10;
                txtbox.TextAlign = TextAlignment;
                txtbox.UseSystemPasswordChar = UseSystemPasswordChar;
            }
 
            G.Clear(BaseColor);
 
            LinearGradientBrush innerBorderBrush = new(new Rectangle(1, 1, Width - 3, Height - 3), BorderColorA, BorderColorB, 90);
            Pen innerBorderPen = new(innerBorderBrush);
            G.DrawRectangle(innerBorderPen, new Rectangle(1, 1, Width - 3, Height - 3));
            G.DrawLine(new(BorderColorC), new Point(1, 1), new Point(Width - 3, 1));
 
            G.DrawRectangle(new(BorderColorD), new Rectangle(0, 0, Width - 1, Height - 1));
            e.Graphics.DrawImage(B, 0, 0);
            G.Dispose();
            B.Dispose();
        }
    }
 
    #endregion
}