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
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
#region Imports
 
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region CircleProgressBar
 
    public class CircleProgressBar : Control
    {
 
        #region Enums
 
        public enum _ProgressShape
        {
            Round,
            Flat
        }
 
        #endregion
        #region Variables
 
        private long _Value;
        private long _Maximum = 100;
        private Color _PercentColor = Color.White;
        private Color _ProgressColor1 = Color.FromArgb(92, 92, 92);
        private Color _ProgressColor2 = Color.FromArgb(92, 92, 92);
        private _ProgressShape ProgressShapeVal;
 
        #endregion
        #region Custom Properties
 
        public long Value
        {
            get => _Value;
            set
            {
                if (value > _Maximum)
                {
                    value = _Maximum;
                }
 
                _Value = value;
                Invalidate();
            }
        }
 
        public long Maximum
        {
            get => _Maximum;
            set
            {
                if (value < 1)
                {
                    value = 1;
                }
 
                _Maximum = value;
                Invalidate();
            }
        }
 
        public Color PercentColor
        {
            get => _PercentColor;
            set
            {
                _PercentColor = value;
                Invalidate();
            }
        }
 
        public Color ProgressColor1
        {
            get => _ProgressColor1;
            set
            {
                _ProgressColor1 = value;
                Invalidate();
            }
        }
 
        public Color ProgressColor2
        {
            get => _ProgressColor2;
            set
            {
                _ProgressColor2 = value;
                Invalidate();
            }
        }
 
        public _ProgressShape ProgressShape
        {
            get => ProgressShapeVal;
            set
            {
                ProgressShapeVal = value;
                Invalidate();
            }
        }
 
        #endregion
        #region EventArgs
 
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            SetStandardSize();
        }
 
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            SetStandardSize();
        }
 
        protected override void OnPaintBackground(PaintEventArgs p)
        {
            base.OnPaintBackground(p);
        }
 
        #endregion
 
        public CircleProgressBar()
        {
            Size = new(130, 130);
            Font = new("Segoe UI", 15);
            MinimumSize = new(100, 100);
            DoubleBuffered = true;
        }
 
        private void SetStandardSize()
        {
            int _Size = Math.Max(Width, Height);
            Size = new(_Size, _Size);
        }
 
        public void Increment(int Val)
        {
            _Value += Val;
            Invalidate();
        }
 
        public void Decrement(int Val)
        {
            _Value -= Val;
            Invalidate();
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            using Bitmap bitmap = new(Width, Height);
            using Graphics graphics = Graphics.FromImage(bitmap);
            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            graphics.Clear(BackColor);
            using (LinearGradientBrush brush = new(ClientRectangle, _ProgressColor1, _ProgressColor2, LinearGradientMode.ForwardDiagonal))
            {
                using Pen pen = new(brush, 14f);
                switch (ProgressShapeVal)
                {
                    case _ProgressShape.Round:
                        pen.StartCap = LineCap.Round;
                        pen.EndCap = LineCap.Round;
                        break;
 
                    case _ProgressShape.Flat:
                        pen.StartCap = LineCap.Flat;
                        pen.EndCap = LineCap.Flat;
                        break;
                }
                graphics.DrawArc(pen, 0x12, 0x12, Width - 0x23 - 2, Height - 0x23 - 2, -90, (int)Math.Round((double)(360.0 / _Maximum * _Value)));
            }
            using (LinearGradientBrush brush2 = new(ClientRectangle, Color.FromArgb(0x34, 0x34, 0x34), Color.FromArgb(0x34, 0x34, 0x34), LinearGradientMode.Vertical))
            {
                graphics.FillEllipse(brush2, 0x18, 0x18, Width - 0x30 - 1, Height - 0x30 - 1);
            }
 
            SizeF MS = graphics.MeasureString(Convert.ToString(Convert.ToInt32(100 / _Maximum * _Value)), Font);
            graphics.DrawString(Convert.ToString(Convert.ToInt32(100 / _Maximum * _Value)), Font, new SolidBrush(_PercentColor), Convert.ToInt32((Width / 2) - (MS.Width / 2)), Convert.ToInt32((Height / 2) - (MS.Height / 2)));
            e.Graphics.DrawImage(bitmap, 0, 0);
            graphics.Dispose();
            bitmap.Dispose();
        }
    }
 
    #endregion
}