yangyin
2025-02-24 b3b65a002fe68b1383314098790f5a153b87765f
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#region Imports
 
using System;
using System.Collections.Generic;
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 ParrotFlatProgressBar
 
    public class ParrotFlatProgressBar : Control
    {
        public ParrotFlatProgressBar()
        {
            base.SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
            base.Size = new Size(300, 5);
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The progress bar style")]
        public Style BarStyle
        {
            get => barStyle;
            set
            {
                barStyle = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The progress value")]
        public int Value
        {
            get => value;
            set
            {
                this.value = value;
                if (this.value < 0)
                {
                    this.value = 0;
                }
                if (this.value > maxValue)
                {
                    this.value = maxValue;
                }
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The progress complete color")]
        public Color CompleteColor
        {
            get => completeColor;
            set
            {
                completeColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The progress complete ios back color")]
        public Color CompleteBackColor
        {
            get => completeBackColor;
            set
            {
                completeBackColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The progress bar border color")]
        public Color BorderColor
        {
            get => borderColor;
            set
            {
                borderColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("Show the progress bar border")]
        public bool ShowBorder
        {
            get => showBorder;
            set
            {
                showBorder = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The progress incompleted color")]
        public Color InocmpletedColor
        {
            get => incompletedColor;
            set
            {
                incompletedColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The progress incompleted ios back color")]
        public Color IncompletedBackColor
        {
            get => incompletedBackColor;
            set
            {
                incompletedBackColor = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The maximum value")]
        public int MaxValue
        {
            get => maxValue;
            set
            {
                maxValue = value;
                if (Value > maxValue)
                {
                    Value = maxValue;
                }
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The positions")]
        public List<float> Positions
        {
            get => _Positions;
            set
            {
                _Positions = value;
                Invalidate();
            }
        }
 
        [Category("Parrot")]
        [Browsable(true)]
        [Description("The colors")]
        public List<Color> Colors
        {
            get => _Colors;
            set
            {
                _Colors = value;
                Invalidate();
            }
        }
 
        private SmoothingMode _SmoothingType = SmoothingMode.HighQuality;
        [Category("Parrot")]
        [Browsable(true)]
        public SmoothingMode SmoothingType
        {
            get => _SmoothingType;
            set
            {
                _SmoothingType = value;
                Invalidate();
            }
        }
 
        private PixelOffsetMode _PixelOffsetType = PixelOffsetMode.HighQuality;
        [Category("Parrot")]
        [Browsable(true)]
        public PixelOffsetMode PixelOffsetType
        {
            get => _PixelOffsetType;
            set
            {
                _PixelOffsetType = value;
                Invalidate();
            }
        }
 
        private CompositingQuality _CompositingQualityType = CompositingQuality.HighQuality;
        [Category("Parrot")]
        [Browsable(true)]
        public CompositingQuality CompositingQualityType
        {
            get => _CompositingQualityType;
            set
            {
                _CompositingQualityType = value;
                Invalidate();
            }
        }
 
        private TextRenderingHint _TextRenderingType = TextRenderingHint.ClearTypeGridFit;
        [Category("Parrot")]
        [Browsable(true)]
        public TextRenderingHint TextRenderingType
        {
            get => _TextRenderingType;
            set
            {
                _TextRenderingType = value;
                Invalidate();
            }
        }
 
        private InterpolationMode _InterpolationType = InterpolationMode.HighQualityBilinear;
        [Category("Parrot")]
        [Browsable(true)]
        public InterpolationMode InterpolationType
        {
            get => _InterpolationType;
            set
            {
                _InterpolationType = value;
                Invalidate();
            }
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            BufferedGraphicsContext bufferedGraphicsContext = BufferedGraphicsManager.Current;
            bufferedGraphicsContext.MaximumBuffer = new Size(base.Width + 1, base.Height + 1);
            bufferedGraphics = bufferedGraphicsContext.Allocate(base.CreateGraphics(), base.ClientRectangle);
 
            bufferedGraphics.Graphics.SmoothingMode = SmoothingType;
            bufferedGraphics.Graphics.InterpolationMode = InterpolationType;
            bufferedGraphics.Graphics.CompositingQuality = CompositingQualityType;
            bufferedGraphics.Graphics.PixelOffsetMode = PixelOffsetType;
            bufferedGraphics.Graphics.TextRenderingHint = TextRenderingType;
 
            bufferedGraphics.Graphics.Clear(BackColor);
 
            if (barStyle == Style.Flat)
            {
                bufferedGraphics.Graphics.FillRectangle(new SolidBrush(incompletedColor), 0, 0, base.Width, base.Height);
                bufferedGraphics.Graphics.FillRectangle(new SolidBrush(completeColor), 0, 0, value * base.Width / maxValue, base.Height);
            }
 
            if (barStyle == Style.IOS)
            {
                bufferedGraphics.Graphics.FillRectangle(new SolidBrush(incompletedBackColor), 0, 0, base.Width, base.Height);
                bufferedGraphics.Graphics.FillRectangle(new SolidBrush(completeBackColor), 0, 0, value * base.Width / maxValue, base.Height);
            }
 
            if (barStyle == Style.Material && Positions.Count == Colors.Count)
            {
                LinearGradientBrush linearGradientBrush = new(new Rectangle(0, 0, base.Width, base.Height), Color.Black, Color.Black, 0f, false)
                {
                    InterpolationColors = new ColorBlend
                    {
                        Positions = Positions.ToArray(),
                        Colors = Colors.ToArray()
                    }
                };
 
                linearGradientBrush.RotateTransform(1f);
                bufferedGraphics.Graphics.FillRectangle(linearGradientBrush, new Rectangle(0, 0, base.Width, base.Height));
                bufferedGraphics.Graphics.FillRectangle(new SolidBrush(incompletedColor), value * base.Width / maxValue, 0, base.Width - (value * base.Width / maxValue), base.Height);
            }
 
            if (ShowBorder)
            {
                bufferedGraphics.Graphics.DrawRectangle(new Pen(BorderColor, 1f), new Rectangle(1, 1, base.Width - 2, base.Height - 2));
            }
 
            bufferedGraphics.Render(e.Graphics);
            base.OnPaint(e);
        }
 
        protected override void OnSizeChanged(EventArgs e)
        {
            Invalidate();
        }
 
        private BufferedGraphics bufferedGraphics;
 
        private Style barStyle = Style.Material;
 
        private int value = 50;
 
        private Color completeColor = Color.FromArgb(1, 119, 215);
 
        private Color completeBackColor = Color.FromArgb(0, 120, 250);
 
        private Color borderColor = Color.Black;
 
        private bool showBorder = true;
 
        private Color incompletedColor = Color.White;
 
        private Color incompletedBackColor = Color.FromArgb(180, 180, 180);
 
        private int maxValue = 100;
 
        private List<float> _Positions = new()
        {
            0f,
            0.2f,
            0.4f,
            0.6f,
            0.8f,
            1f
        };
 
        private List<Color> _Colors = new()
        {
            Color.FromArgb(76, 217, 100),
            Color.FromArgb(85, 205, 205),
            Color.FromArgb(2, 124, 255),
            Color.FromArgb(130, 75, 180),
            Color.FromArgb(255, 0, 150),
            Color.FromArgb(255, 45, 85)
        };
 
        public enum Style
        {
            Flat,
            Material,
            IOS
        }
    }
 
    #endregion
}