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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Colors;
using DPumpHydr.WinFrmUI.RLT.Util;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region HopeRoundPrgoressBar
 
    public class HopeRoundProgressBar : Control
    {
 
        private readonly int tempValue = 0;
        private int _valueNumber = 0;
        public int ValueNumber
        {
            get => _valueNumber;
            set
            {
                _valueNumber = value > 100 ? 100 : (value < 0 ? 0 : value);
                Invalidate();
            }
        }
 
        private readonly float _roundWidth = 6;
 
        private bool _isError = false;
        public bool IsError
        {
            get => _isError;
            set
            {
                _isError = value;
                Invalidate();
            }
        }
 
        public string PercentText { get; set; } = "%";
        public Color BorderColor { get; set; } = HopeColors.OneLevelBorder;
        public Color DangerColor { get; set; } = HopeColors.Danger;
        public Color DangerTextColorA { get; set; } = HopeColors.Danger;
        public Color DangerTextColorB { get; set; } = HopeColors.Danger;
        public Color FullTextColorA { get; set; } = HopeColors.Success;
        public Color FullTextColorB { get; set; } = HopeColors.Success;
        public Color BarColor { get; set; } = HopeColors.PrimaryColor;
        public Color FullBarColor { get; set; } = HopeColors.Success;
 
        #region Events
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            Width = Height;
        }
        #endregion
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics graphics = e.Graphics;
            graphics.SmoothingMode = SmoothingMode.HighQuality;
            graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
            graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            graphics.Clear(Parent.BackColor);
 
            graphics.FillEllipse(new SolidBrush(BorderColor), new Rectangle(0, 0, Width, Height));
 
            if (_isError)
            {
                graphics.FillPie(new SolidBrush(DangerColor), new Rectangle(0, 0, Width, Width), 0, _valueNumber * 3.6f);
 
                graphics.FillEllipse(new SolidBrush(BackColor), new RectangleF(_roundWidth, _roundWidth, Width - (_roundWidth * 2), Width - (_roundWidth * 2)));
                graphics.DrawLine(new(DangerTextColorA, 2f), (Width / 2) - 6, (Height / 2) - 6, (Width / 2) + 6, (Height / 2) + 6);
                graphics.DrawLine(new(DangerTextColorB, 2f), (Width / 2) - 6, (Height / 2) + 6, (Width / 2) + 6, (Height / 2) - 6);
            }
            else
            {
                if (_valueNumber == 100)
                {
                    graphics.FillPie(new SolidBrush(FullBarColor), new Rectangle(0, 0, Width, Width), 0, _valueNumber * 3.6f);
                    graphics.FillEllipse(new SolidBrush(BackColor), new RectangleF(_roundWidth, _roundWidth, Width - (_roundWidth * 2), Width - (_roundWidth * 2)));
                    graphics.DrawLine(new(FullTextColorA, 2f), (Width / 2) - 6, Height / 2, (Width / 2) - 3, (Height / 2) + 6);
                    graphics.DrawLine(new(FullTextColorB, 2f), (Width / 2) + 6, (Height / 2) - 6, (Width / 2) - 3, (Height / 2) + 6);
                }
                else
                {
                    graphics.FillPie(new SolidBrush(BarColor), new Rectangle(0, 0, Width, Width), 0, _valueNumber * 3.6f);
                    graphics.FillEllipse(new SolidBrush(BackColor), new RectangleF(_roundWidth, _roundWidth, Width - (_roundWidth * 2), Width - (_roundWidth * 2)));
                    graphics.DrawString(_valueNumber.ToString() + PercentText, Font, new SolidBrush(ForeColor), new RectangleF(_roundWidth, _roundWidth, Width - (_roundWidth * 2), Width - (_roundWidth * 2)), HopeStringAlign.Center);
                }
            }
        }
 
        public HopeRoundProgressBar()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
            DoubleBuffered = true;
            Font = new("Segoe UI", 12f);
            BackColor = Color.White;
            ForeColor = HopeColors.PrimaryColor;
        }
    }
 
    #endregion
}