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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Util;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Threading;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region RibbonProgressBarLeft
 
    public class RibbonProgressBarLeft : Control
    {
 
        #region " Control Help - Properties & Flicker Control "
        private int OFS = 0;
        private readonly int Speed = 50;
 
        private int _Maximum = 100;
        public int Maximum
        {
            get => _Maximum;
            set
            {
                _Maximum = value;
                Invalidate();
            }
        }
 
        private int _Value = 0;
        public int Value
        {
            get => _Value;
            set
            {
                _Value = value;
                Invalidate();
            }
        }
 
        private bool _ShowPercentage = false;
        public bool ShowPercentage
        {
            get => _ShowPercentage;
            set
            {
                _ShowPercentage = value;
                Invalidate();
            }
        }
 
        private bool _ShowEdge = false;
        public bool ShowEdge
        {
            get => _ShowEdge;
            set
            {
                _ShowEdge = value;
                Invalidate();
            }
        }
 
        protected override void CreateHandle()
        {
            base.CreateHandle();
            Thread T = new(Animate)
            {
                IsBackground = true
            };
        }
 
        public void Animate()
        {
            while (true)
            {
                if (OFS <= Width)
                {
                    OFS += 1;
                }
                else
                {
                    OFS = 0;
                }
 
                Invalidate();
                Thread.Sleep(Speed);
            }
        }
 
        private SmoothingMode _SmoothingType = SmoothingMode.HighQuality;
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        private string _PercentageText = "%";
        public string PercentageText
        {
            get => _PercentageText;
            set
            {
                _PercentageText = value;
                Invalidate();
            }
        }
 
        private Color _ProgressBorderColorA = Color.FromArgb(150, 97, 94, 90);
        public Color ProgressBorderColorA
        {
            get => _ProgressBorderColorA;
            set
            {
                _ProgressBorderColorA = value;
                Invalidate();
            }
        }
 
        private Color _ProgressBorderColorB = Color.FromArgb(153, 151, 155);
        public Color ProgressBorderColorB
        {
            get => _ProgressBorderColorB;
            set
            {
                _ProgressBorderColorB = value;
                Invalidate();
            }
        }
 
        private Color _EdgeColor = Color.FromArgb(125, 97, 94, 90);
        public Color EdgeColor
        {
            get => _EdgeColor;
            set
            {
                _EdgeColor = value;
                Invalidate();
            }
        }
 
        private Color _BorderColor = Color.FromArgb(117, 120, 117);
        public Color BorderColor
        {
            get => _BorderColor;
            set
            {
                _BorderColor = value;
                Invalidate();
            }
        }
 
        private Color _ColorA = Color.FromArgb(203, 201, 205);
        public Color ColorA
        {
            get => _ColorA;
            set
            {
                _ColorA = value;
                Invalidate();
            }
        }
 
        private Color _ColorB = Color.FromArgb(188, 186, 190);
        public Color ColorB
        {
            get => _ColorB;
            set
            {
                _ColorB = value;
                Invalidate();
            }
        }
 
        private Color _BaseColor = Color.FromArgb(75, Color.White);
        public Color BaseColor
        {
            get => _BaseColor;
            set
            {
                _BaseColor = value;
                Invalidate();
            }
        }
 
        private Color _ProgressColorA = Color.FromArgb(203, 201, 205);
        public Color ProgressColorA
        {
            get => _ProgressColorA;
            set
            {
                _ProgressColorA = value;
                Invalidate();
            }
        }
 
        private Color _ProgressColorB = Color.FromArgb(188, 186, 190);
        public Color ProgressColorB
        {
            get => _ProgressColorB;
            set
            {
                _ProgressColorB = value;
                Invalidate();
            }
        }
 
        private Color _ProgressLineColorA = Color.FromArgb(40, Color.White);
        public Color ProgressLineColorA
        {
            get => _ProgressLineColorA;
            set
            {
                _ProgressLineColorA = value;
                Invalidate();
            }
        }
 
        private Color _ProgressLineColorB = Color.FromArgb(20, Color.White);
        public Color ProgressLineColorB
        {
            get => _ProgressLineColorB;
            set
            {
                _ProgressLineColorB = value;
                Invalidate();
            }
        }
 
        private HatchStyle _HatchType = HatchStyle.DarkUpwardDiagonal;
        public HatchStyle HatchType
        {
            get => _HatchType;
            set
            {
                _HatchType = value;
                Invalidate();
            }
        }
        #endregion
 
        public RibbonProgressBarLeft() : base()
        {
            DoubleBuffered = true;
            SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
            ForeColor = Color.Black;
            BackColor = Color.Transparent;
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
 
            G.SmoothingMode = SmoothingType;
 
            int intValue = Convert.ToInt32(Convert.ToDouble(_Value) / Convert.ToDouble(_Maximum) * Width);
            G.Clear(BackColor);
 
            LinearGradientBrush gB = new(new Rectangle(0, 0, Width - 1, Height - 1), ColorA, ColorB, 90);
            G.FillPath(gB, DrawRibbon.RoundRect(new Rectangle(0, 0, Width - 1, Height - 1), 1));
            G.DrawPath(new(new SolidBrush(BaseColor)), DrawRibbon.RoundRect(new Rectangle(1, 1, Width - 3, Height - 3), 1));
 
            LinearGradientBrush g1 = new(new Rectangle(2, 2, intValue - 1, Height - 2), ProgressColorA, ProgressColorB, 90);
            G.FillPath(g1, DrawRibbon.RoundRect(new Rectangle(0, 0, intValue - 1, Height - 2), 1));
            HatchBrush h1 = new(HatchType, ProgressLineColorA, ProgressLineColorB);
            G.FillPath(h1, DrawRibbon.RoundRect(new Rectangle(0, 0, intValue - 1, Height - 2), 1));
 
            if (ShowEdge)
            {
                G.DrawPath(new(EdgeColor), DrawRibbon.RoundRect(new Rectangle(0, 1, Width - 1, Height - 3), 2));
            }
 
            G.DrawPath(new(BorderColor), DrawRibbon.RoundRect(new Rectangle(0, 0, Width - 1, Height - 1), 2));
 
            G.DrawPath(new(ProgressBorderColorA), DrawRibbon.RoundRect(new Rectangle(0, 0, intValue - 1, Height - 1), 2));
            G.DrawPath(new(ProgressBorderColorB), DrawRibbon.RoundRect(new Rectangle(0, 0, intValue - 1, Height - 1), 2));
            //colored bar outline
 
            if (_ShowPercentage)
            {
                G.DrawString(Convert.ToString(string.Concat(Value, PercentageText)), Font, new SolidBrush(ForeColor), new Rectangle(0, 0, Width - 1, Height - 1), new StringFormat
                {
                    Alignment = StringAlignment.Center,
                    LineAlignment = StringAlignment.Center
                });
            }
 
            e.Graphics.DrawImage(B, 0, 0);
            G.Dispose();
            B.Dispose();
        }
    }
 
    #endregion
}