tangxu
2024-12-16 23fadc9cb0c09b665a1bbcef7eaf16f916045dc4
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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Util;
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 FoxNumeric
 
    public class FoxNumeric : Control
    {
        private Graphics G;
 
        private bool IsEnabled;
 
        private int _Value;
        public int Value
        {
            get => _Value;
            set
            {
                if (value > _Max)
                {
                    _Value = _Max;
                    return;
                }
                if (value < Min)
                {
                    _Value = _Min;
                    return;
                }
                _Value = value;
                Invalidate();
            }
        }
 
        private int _Max = 100;
        public int Max
        {
            get => _Max;
            set
            {
                if (value == _Min || value < _Min)
                {
                    _Max = _Min + 1;
                    Invalidate();
                }
                else
                {
                    _Max = value;
                }
            }
        }
 
        private int _Min = 0;
        public int Min
        {
            get => _Min;
            set
            {
                if (value > _Max || value == _Max)
                {
                    _Min = _Max - 1;
                    Invalidate();
                }
                else
                {
                    _Min = value;
                }
            }
        }
 
        public new bool Enabled
        {
            get => EnabledCalc;
            set
            {
                IsEnabled = value;
                Invalidate();
            }
        }
 
        [DisplayName("Enabled")]
        public bool EnabledCalc
        {
            get => IsEnabled;
            set
            {
                Enabled = value;
                Invalidate();
            }
        }
 
        public Color BorderColor { get; set; } = FoxLibrary.ColorFromHex("#C8C8C8");
        public Color DisabledBorderColor { get; set; } = FoxLibrary.ColorFromHex("#E6E6E6");
        public Color ButtonTextColor { get; set; } = FoxLibrary.ColorFromHex("#56626E");
        public Color DisabledTextColor { get; set; } = FoxLibrary.ColorFromHex("#A6B2BE");
        public Color DisabledButtonTextColor { get; set; } = FoxLibrary.ColorFromHex("#BAC6D2");
 
        public FoxNumeric()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
 
            Enabled = true;
            DoubleBuffered = true;
            Font = new("Segoe UI", 10);
            BackColor = Color.Transparent;
            ForeColor = FoxLibrary.ColorFromHex("#424E5A");
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            G = e.Graphics;
            G.SmoothingMode = SmoothingMode.HighQuality;
            G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
 
            //G.Clear(BackColor);
 
            if (Enabled)
            {
                using (Pen Border = new(BorderColor))
                {
                    G.DrawPath(Border, FoxLibrary.RoundRect(FoxLibrary.FullRectangle(Size, true), 2));
                    G.DrawPath(Border, FoxLibrary.RoundRect(new Rectangle(Width - 20, 4, 15, 18), 2));
                }
 
                using (SolidBrush TextColor = new(ForeColor))
                {
                    FoxLibrary.CenterString(G, Value.ToString(), Font, TextColor.Color, new Rectangle(-10, 0, Width, Height));
                }
 
                using SolidBrush SignColor = new(ButtonTextColor);
                using Font SignFont = new("Marlett", 10);
                G.DrawString("t", SignFont, SignColor, new Point(Width - 20, 4));
                G.DrawString("u", SignFont, SignColor, new Point(Width - 20, 10));
            }
            else
            {
                using (Pen Border = new(DisabledBorderColor))
                {
                    G.DrawPath(Border, FoxLibrary.RoundRect(FoxLibrary.FullRectangle(Size, true), 2));
                    G.DrawPath(Border, FoxLibrary.RoundRect(new Rectangle(Width - 20, 4, 15, 18), 2));
                }
 
                using (SolidBrush TextColor = new(DisabledTextColor))
                {
                    FoxLibrary.CenterString(G, Value.ToString(), Font, TextColor.Color, new Rectangle(-10, 0, Width, Height));
                }
 
                using SolidBrush SignColor = new(DisabledButtonTextColor);
                using Font SignFont = new("Marlett", 10);
                G.DrawString("t", SignFont, SignColor, new Point(Width - 20, 4));
                G.DrawString("u", SignFont, SignColor, new Point(Width - 20, 10));
            }
 
            base.OnPaint(e);
        }
 
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
 
            if (Enabled)
            {
                if (e.X > Width - 20 & e.Y < 10)
                {
                    Value += 1;
                }
                else if (e.X > Width - 20 & e.Y > 10)
                {
                    Value -= 1;
                }
            }
        }
 
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
 
            if (Enabled)
            {
                if (e.X > Width - 20 & e.Y < 10)
                {
                    Cursor = Cursors.Hand;
                }
                else if (e.X > Width - 20 & e.Y > 10)
                {
                    Cursor = Cursors.Hand;
                }
                else
                {
                    Cursor = Cursors.Default;
                }
            }
        }
 
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            Size = new(Width, 27);
        }
    }
 
    #endregion
}