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
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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Util;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region AloneButton
 
    public class AloneButton : Control
    {
        public enum MouseState : byte
        {
            None,
            Over,
            Down
        }
 
        public delegate void ClickEventHandler(object sender, EventArgs e);
 
        private Graphics G;
 
        private MouseState State;
 
        private bool _EnabledCalc;
 
        [DebuggerBrowsable(DebuggerBrowsableState.Never), CompilerGenerated]
        private ClickEventHandler ClickEvent;
 
        public new event ClickEventHandler Click
        {
            [CompilerGenerated]
            add
            {
                ClickEventHandler clickEventHandler = ClickEvent;
                ClickEventHandler clickEventHandler2;
                do
                {
                    clickEventHandler2 = clickEventHandler;
                    ClickEventHandler value2 = (ClickEventHandler)Delegate.Combine(clickEventHandler2, value);
                    clickEventHandler = Interlocked.CompareExchange(ref ClickEvent, value2, clickEventHandler2);
                }
                while (clickEventHandler != clickEventHandler2);
            }
            [CompilerGenerated]
            remove
            {
                ClickEventHandler clickEventHandler = ClickEvent;
                ClickEventHandler clickEventHandler2;
                do
                {
                    clickEventHandler2 = clickEventHandler;
                    ClickEventHandler value2 = (ClickEventHandler)Delegate.Remove(clickEventHandler2, value);
                    clickEventHandler = Interlocked.CompareExchange(ref ClickEvent, value2, clickEventHandler2);
                }
                while (clickEventHandler != clickEventHandler2);
            }
        }
 
        public new bool Enabled
        {
            get => EnabledCalc;
            set
            {
                _EnabledCalc = value;
                Invalidate();
            }
        }
 
        [DisplayName("Enabled")]
        public bool EnabledCalc
        {
            get => _EnabledCalc;
            set
            {
                Enabled = value;
                Invalidate();
            }
        }
 
        public AloneButton()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
 
            Enabled = true;
            Size = new(120, 40);
            DoubleBuffered = true;
            Cursor = Cursors.Hand;
            Font = new("Segoe UI", 9f);
            BackColor = Color.Transparent;
            ForeColor = AloneLibrary.ColorFromHex("#7C858E");
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            G = e.Graphics;
            G.SmoothingMode = SmoothingMode.HighQuality;
            G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
 
            //G.Clear(BackColor);
 
            base.OnPaint(e);
 
            if (Enabled)
            {
                MouseState state = State;
                if (state != MouseState.Over)
                {
                    if (state != MouseState.Down)
                    {
                        using SolidBrush solidBrush = new(AloneLibrary.ColorFromHex("#F6F6F6"));
                        G.FillPath(solidBrush, AloneLibrary.RoundRect(AloneLibrary.FullRectangle(base.Size, true), 3, AloneLibrary.RoundingStyle.All));
                    }
                    else
                    {
                        using SolidBrush solidBrush2 = new(AloneLibrary.ColorFromHex("#F0F0F0"));
                        G.FillPath(solidBrush2, AloneLibrary.RoundRect(AloneLibrary.FullRectangle(base.Size, true), 3, AloneLibrary.RoundingStyle.All));
                    }
                }
                else
                {
                    using SolidBrush solidBrush3 = new(AloneLibrary.ColorFromHex("#FDFDFD"));
                    G.FillPath(solidBrush3, AloneLibrary.RoundRect(AloneLibrary.FullRectangle(base.Size, true), 3, AloneLibrary.RoundingStyle.All));
                }
                using (Pen pen = new(AloneLibrary.ColorFromHex("#C3C3C3")))
                {
                    G.DrawPath(pen, AloneLibrary.RoundRect(AloneLibrary.FullRectangle(base.Size, true), 3, AloneLibrary.RoundingStyle.All));
                    AloneLibrary.CenterString(G, Text, Font, ForeColor, AloneLibrary.FullRectangle(base.Size, false));
                }
                Cursor = Cursors.Hand;
            }
            else
            {
                using (SolidBrush solidBrush4 = new(AloneLibrary.ColorFromHex("#F3F4F7")))
                {
                    using Pen pen2 = new(AloneLibrary.ColorFromHex("#DCDCDC"));
                    G.FillPath(solidBrush4, AloneLibrary.RoundRect(AloneLibrary.FullRectangle(base.Size, true), 3, AloneLibrary.RoundingStyle.All));
                    G.DrawPath(pen2, AloneLibrary.RoundRect(AloneLibrary.FullRectangle(base.Size, true), 3, AloneLibrary.RoundingStyle.All));
                    AloneLibrary.CenterString(G, Text, Font, AloneLibrary.ColorFromHex("#D0D3D7"), AloneLibrary.FullRectangle(base.Size, false));
                }
                Cursor = Cursors.Default;
            }
        }
 
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);
            State = MouseState.Over;
            Invalidate();
        }
 
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            State = MouseState.None;
            Invalidate();
        }
 
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            bool enabled = Enabled;
            if (enabled)
            {
                ClickEvent?.Invoke(this, e);
            }
 
            State = MouseState.Over;
            Invalidate();
        }
 
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            State = MouseState.Down;
            Invalidate();
        }
    }
 
    #endregion
}