yangyin
2024-10-22 90573e299e2eea301a0ad8585a7e6b95d7a798bb
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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Util;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region ThunderProgressBar
 
    public class ThunderProgressBar : Control
    {
        private int _Maximum = 100;
 
        public int Maximum
        {
            get => _Maximum;
            set
            {
                _Maximum = value;
                Invalidate();
            }
        }
        private int _Value = 0;
        public int Value
        {
            get
            {
                if (_Value == 0)
                {
                    return 0;
                }
                else
                {
                    return _Value;
                }
            }
            set
            {
                _Value = value;
                if (_Value > _Maximum)
                {
                    _Value = _Maximum;
                }
 
                Invalidate();
            }
        }
        private bool _ShowPercentage = false;
        public bool ShowPercentage
        {
            get => _ShowPercentage;
            set
            {
                _ShowPercentage = value;
                Invalidate();
            }
        }
 
        public ThunderProgressBar() : base()
        {
            DoubleBuffered = true;
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.UserPaint, true);
            BackColor = Color.Transparent;
            ForeColor = Color.WhiteSmoke;
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
 
            G.SmoothingMode = SmoothingMode.HighQuality;
 
            double val = (double)_Value / _Maximum;
            int intValue = Convert.ToInt32(val * Width);
            G.Clear(BackColor);
            Color C1 = Color.FromArgb(174, 195, 30);
            Color C2 = Color.FromArgb(141, 153, 16);
            Rectangle R1 = new(0, 0, Width - 1, Height - 1);
            Rectangle R2 = new(0, 0, intValue - 1, Height - 1);
            Rectangle R3 = new(0, 0, intValue - 1, Height - 2);
            GraphicsPath GP1 = DrawThunder.RoundRect(R1, 1);
            GraphicsPath GP2 = DrawThunder.RoundRect(R2, 2);
            GraphicsPath GP3 = DrawThunder.RoundRect(R3, 1);
            LinearGradientBrush gB = new(R1, Color.FromArgb(26, 26, 26), Color.FromArgb(30, 30, 30), 90);
            LinearGradientBrush g1 = new(new Rectangle(2, 2, intValue - 1, Height - 2), C1, C2, 90);
            HatchBrush h1 = new(HatchStyle.DarkUpwardDiagonal, Color.FromArgb(50, C1), Color.FromArgb(25, C2));
            Pen P1 = new(Color.Black);
 
            G.FillPath(gB, GP1);
            G.FillPath(g1, GP3);
            G.FillPath(h1, GP3);
            G.DrawPath(P1, GP1);
            G.DrawPath(new(Color.FromArgb(150, 97, 94, 90)), GP2);
            G.DrawPath(P1, GP2);
 
            if (_ShowPercentage)
            {
                G.DrawString(Convert.ToString(string.Concat(Value, "%")), Font, new SolidBrush(ForeColor), R1, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
            }
 
            e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
            G.Dispose();
            B.Dispose();
        }
    }
 
    #endregion
}