tangxu
2025-02-10 e40718947b5aa9205c87a7478aa86c37a82e0510
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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Colors;
using DPumpHydr.WinFrmUI.RLT.Util;
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 ForeverGroupBox
 
    public class ForeverGroupBox : ContainerControl
    {
        private int W;
        private int H;
 
        [Category("Colors")]
        public Color BaseColor { get; set; } = Color.FromArgb(60, 70, 73);
 
        [Category("Colors")]
        public Color TextColor { get; set; } = ForeverLibrary.ForeverColor;
 
        [Category("Colors")]
        public Color ArrowColorH { get; set; } = Color.FromArgb(60, 70, 73);
 
        [Category("Colors")]
        public Color ArrowColorF { get; set; } = Color.FromArgb(60, 70, 73);
 
        [Category("Options")]
        public bool ShowText { get; set; } = true;
 
        [Category("Options")]
        public bool ShowArrow { get; set; } = true;
 
        public ForeverGroupBox()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
            DoubleBuffered = true;
            BackColor = Color.Transparent;
            Size = new(240, 180);
            Font = new("Segoe UI", 10);
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            //UpdateColors();
 
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
            W = Width - 1;
            H = Height - 1;
 
            GraphicsPath GP = new();
            GraphicsPath GP2 = new();
            GraphicsPath GP3 = new();
            Rectangle Base = new(8, 8, W - 16, H - 16);
 
            Graphics _with7 = G;
            _with7.SmoothingMode = SmoothingMode.HighQuality;
            _with7.PixelOffsetMode = PixelOffsetMode.HighQuality;
            _with7.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            _with7.Clear(BackColor);
 
            //-- Base
            GP = ForeverLibrary.RoundRec(Base, 8);
            _with7.FillPath(new SolidBrush(BaseColor), GP);
 
            //-- Arrows
            if (ShowArrow)
            {
                GP2 = ForeverLibrary.DrawArrow(28, 2, false);
                _with7.FillPath(new SolidBrush(ArrowColorH), GP2);
                GP3 = ForeverLibrary.DrawArrow(28, 8, true);
                _with7.FillPath(new SolidBrush(ArrowColorF), GP3);
            }
 
            //-- if ShowText
            if (ShowText)
            {
                _with7.DrawString(Text, Font, new SolidBrush(TextColor), new Rectangle(16, 16, W, H), ForeverLibrary.NearSF);
            }
 
            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);
 
            TextColor = Colors.Forever;
        }
    }
 
    #endregion
}