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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Util;
using DPumpHydr.WinFrmUI.RLT.Util.FoxBase;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region FoxButton
 
    public class FoxButton : ButtonFoxBase
    {
        private Graphics G;
 
        public Color BaseColor { get; set; } = FoxLibrary.ColorFromHex("#F9F9F9");
        public Color OverColor { get; set; } = FoxLibrary.ColorFromHex("#F2F2F2");
        public Color DownColor { get; set; } = FoxLibrary.ColorFromHex("#E8E8E8");
        public Color BorderColor { get; set; } = FoxLibrary.ColorFromHex("#C1C1C1");
        public Color DisabledBaseColor { get; set; } = FoxLibrary.ColorFromHex("#F9F9F9");
        public Color DisabledTextColor { get; set; } = FoxLibrary.ColorFromHex("#A6B2BE");
        public Color DisabledBorderColor { get; set; } = FoxLibrary.ColorFromHex("#D1D1D1");
 
        public FoxButton() : base()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
 
            Font = new("Segoe UI", 10);
            BackColor = Color.Transparent;
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            G = e.Graphics;
            G.SmoothingMode = SmoothingMode.HighQuality;
            G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
 
            //G.Clear(BackColor);
 
            if (Enabled)
            {
                switch (State)
                {
                    case FoxLibrary.MouseState.None:
                        using (SolidBrush Background = new(BaseColor))
                        {
                            G.FillPath(Background, FoxLibrary.RoundRect(FoxLibrary.FullRectangle(Size, true), 2));
                        }
 
                        break;
                    case FoxLibrary.MouseState.Over:
 
                        using (SolidBrush Background = new(OverColor))
                        {
                            G.FillPath(Background, FoxLibrary.RoundRect(FoxLibrary.FullRectangle(Size, true), 2));
                        }
 
                        break;
                    case FoxLibrary.MouseState.Down:
                        using (SolidBrush Background = new(DownColor))
                        {
                            G.FillPath(Background, FoxLibrary.RoundRect(FoxLibrary.FullRectangle(Size, true), 2));
                        }
 
                        break;
                }
 
                using (Pen Border = new(BorderColor))
                {
                    G.DrawPath(Border, FoxLibrary.RoundRect(FoxLibrary.FullRectangle(Size, true), 2));
                }
 
                using SolidBrush TextColor = new(ForeColor);
                FoxLibrary.CenterString(G, Text, Font, TextColor.Color, new Rectangle(3, 0, Width, Height));
            }
            else
            {
                using (SolidBrush Background = new(DisabledBaseColor))
                {
                    G.FillPath(Background, FoxLibrary.RoundRect(FoxLibrary.FullRectangle(Size, true), 2));
                }
 
                using (SolidBrush TextColor = new(DisabledTextColor))
                {
                    FoxLibrary.CenterString(G, Text, Font, TextColor.Color, new Rectangle(3, 0, Width, Height));
                }
 
                using Pen Border = new(DisabledBorderColor);
                G.DrawPath(Border, FoxLibrary.RoundRect(FoxLibrary.FullRectangle(Size, true), 2));
            }
 
            base.OnPaint(e);
        }
 
    }
 
    #endregion
}