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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Colors;
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 ForeverProgressBar
 
    public class ForeverProgressBar : Control
    {
        private int W;
        private int H;
        private int _Value = 0;
        private int _Maximum = 100;
 
        [Category("Control")]
        public int Maximum
        {
            get => _Maximum;
            set
            {
                if (value < _Value)
                {
                    _Value = value;
                }
 
                _Maximum = value;
                Invalidate();
            }
        }
 
        [Category("Control")]
        public int Value
        {
            get => _Value;/*
                switch (_Value)
                {
                    case 0:
                        return 0;
                        Invalidate();
                        break;
                    default:
                        return _Value;
                        Invalidate();
                        break;
                }
                */
            set
            {
                if (value > _Maximum)
                {
                    value = _Maximum;
                    Invalidate();
                }
 
                _Value = value;
                Invalidate();
            }
        }
 
        public bool Pattern { get; set; } = true;
 
        public bool MoveBalloon { get; set; } = true;
 
        public bool ShowBalloon { get; set; } = true;
 
        public bool PercentSign { get; set; } = false;
 
        [Category("Colors")]
        public Color BaseColor { get; set; } = Color.FromArgb(45, 47, 49);
 
        [Category("Colors")]
        public Color ProgressColor { get; set; } = ForeverLibrary.ForeverColor;
 
        [Category("Colors")]
        public Color DarkerProgress { get; set; } = Color.FromArgb(23, 148, 92);
 
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            Height = 42;
        }
 
        protected override void CreateHandle()
        {
            base.CreateHandle();
            Height = 42;
        }
 
        public void Increment(int Amount)
        {
            Value += Amount;
        }
 
        public ForeverProgressBar()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
 
            DoubleBuffered = true;
            //BackColor = Color.FromArgb(60, 70, 73);
            BackColor = Color.Transparent;
            ForeColor = ProgressColor;
            Height = 42;
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            //UpdateColors();
 
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
            W = Width;
            H = Height - 1;
 
            Rectangle Base = new(0, 24, W, H);
            GraphicsPath GP = new();
            GraphicsPath GP2 = new();
            GraphicsPath GP3 = new();
 
            Graphics _with15 = G;
            _with15.SmoothingMode = SmoothingMode.HighQuality;
            _with15.PixelOffsetMode = PixelOffsetMode.HighQuality;
            _with15.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
 
            _with15.Clear(BackColor);
 
            //-- Progress Value
            //int iValue = Convert.ToInt32(((float)_Value) / ((float)(_Maximum * Width)));
            float percent = _Value / ((float)_Maximum);
            int iValue = (int)(percent * Width);
 
            switch (Value)
            {
                case 0 or 100:
                    //-- Base
                    _with15.FillRectangle(new SolidBrush(BaseColor), Base);
                    //--Progress
                    _with15.FillRectangle(new SolidBrush(ProgressColor), new Rectangle(0, 24, iValue, H - 1));
 
                    if (ShowBalloon && !MoveBalloon)
                    {
                        float percent2 = 50 / ((float)_Maximum);
                        iValue = (int)(percent2 * Width);
 
                        //-- Balloon
                        Rectangle Balloon = new(iValue - 18, 0, 34, 16);
                        GP2 = ForeverLibrary.RoundRec(Balloon, 4);
                        _with15.FillPath(new SolidBrush(BaseColor), GP2);
 
                        //-- Arrow
                        GP3 = ForeverLibrary.DrawArrow(iValue - 7, 16, true);
                        _with15.FillPath(new SolidBrush(BaseColor), GP3);
 
                        //-- Value > You can add "%" > value & "%"
                        string text = PercentSign ? Value.ToString() + "%" : Value.ToString();
                        int wOffset = PercentSign ? iValue - 15 : iValue - 11;
 
                        _with15.DrawString(text, new Font("Segoe UI", 10), new SolidBrush(ForeColor), new Rectangle(Value == 100 ? wOffset - 4 : Value == 0 ? wOffset + 4 : wOffset, -2, W, H), ForeverLibrary.NearSF);
                    }
                    break;
                default:
                    //-- Base
                    _with15.FillRectangle(new SolidBrush(BaseColor), Base);
 
                    //--Progress
                    GP.AddRectangle(new Rectangle(0, 24, iValue, H - 1));
                    _with15.FillPath(new SolidBrush(ProgressColor), GP);
 
                    if (Pattern)
                    {
                        //-- Hatch Brush
                        HatchBrush HB = new(HatchStyle.Plaid, DarkerProgress, ProgressColor);
                        _with15.FillRectangle(HB, new Rectangle(0, 24, iValue, H - 1));
                    }
 
                    if (ShowBalloon)
                    {
                        if (!MoveBalloon)
                        {
                            float percent2 = 50 / ((float)_Maximum);
                            iValue = (int)(percent2 * Width);
                        }
 
                        //-- Balloon
                        Rectangle Balloon = new(iValue - 18, 0, 34, 16);
                        GP2 = ForeverLibrary.RoundRec(Balloon, 4);
                        _with15.FillPath(new SolidBrush(BaseColor), GP2);
 
                        //-- Arrow
                        GP3 = ForeverLibrary.DrawArrow(iValue - 7, 16, true);
                        _with15.FillPath(new SolidBrush(BaseColor), GP3);
 
                        //-- Value > You can add "%" > value & "%"
                        string text = PercentSign ? Value.ToString() + "%" : Value.ToString();
                        int wOffset = PercentSign ? iValue - 15 : iValue - 11;
 
                        _with15.DrawString(text, new Font("Segoe UI", 10), new SolidBrush(ForeColor), new Rectangle(Value <= 9 ? wOffset + 4 : wOffset, -2, W, H), ForeverLibrary.NearSF);
                    }
 
                    break;
            }
 
            base.OnPaint(e);
 
            G.Dispose();
 
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.DrawImageUnscaled(B, 0, 0);
 
            B.Dispose();
        }
 
        private void UpdateColors()
        {
            ForeverColors Colors = ForeverLibrary.GetColors(this);
 
            ProgressColor = Colors.Forever;
        }
    }
 
    #endregion
}