tangxu
2024-12-24 91105b77c916d06dd30380e20594e29f85eae3da
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
#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 ThunderButton
 
    public class ThunderButton : Control
    {
        private MouseStateThunder State = MouseStateThunder.None;
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            State = MouseStateThunder.Down;
            Invalidate();
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            State = MouseStateThunder.Over;
            Invalidate();
        }
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);
            State = MouseStateThunder.Over;
            Invalidate();
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            State = MouseStateThunder.None;
            Invalidate();
        }
        public ThunderButton()
        {
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.UserPaint, true);
            BackColor = Color.Transparent;
            ForeColor = Color.WhiteSmoke;
            DoubleBuffered = true;
            Cursor = Cursors.Hand;
            Size = new(120, 40);
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
            Rectangle ClientRectangle = new(0, 0, Width - 1, Height - 1);
            base.OnPaint(e);
            G.Clear(BackColor);
            Font drawFont = new("Tahoma", 8, FontStyle.Bold);
            G.SmoothingMode = SmoothingMode.HighQuality;
            Rectangle R1 = new(0, 0, Width - 125, 35 / 2);
            Rectangle R2 = new(5, Height - 10, Width - 11, 5);
            Rectangle R3 = new(6, Height - 9, Width - 13, 3);
            Rectangle R4 = new(1, 1, Width - 3, Height - 3);
            Rectangle R5 = new(1, 0, Width - 1, Height - 1);
            Rectangle R6 = new(0, -1, Width - 1, Height - 1);
            LinearGradientBrush lgb = new(ClientRectangle, Color.FromArgb(66, 67, 70), Color.FromArgb(43, 44, 48), 90);
            LinearGradientBrush botbar = new(R2, Color.FromArgb(44, 45, 49), Color.FromArgb(45, 46, 50), 90);
            LinearGradientBrush fill = new(R3, Color.FromArgb(174, 195, 30), Color.FromArgb(141, 153, 16), 90);
            Pen o = new(Color.FromArgb(50, 50, 50), 1);
            StringFormat format = new() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
            LinearGradientBrush gloss;
            if (State == MouseStateThunder.Over)
            {
                gloss = new(R1, Color.FromArgb(15, Color.FromArgb(26, 26, 26)), Color.FromArgb(1, 255, 255, 255), 90);
            }
            else if (State == MouseStateThunder.Down)
            {
                gloss = new(R1, Color.FromArgb(100, Color.FromArgb(26, 26, 26)), Color.FromArgb(1, 255, 255, 255), 90);
            }
            else
            {
                gloss = new(R1, Color.FromArgb(75, Color.FromArgb(26, 26, 26)), Color.FromArgb(3, 255, 255, 255), 90);
            }
 
            G.FillPath(lgb, DrawThunder.RoundRect(ClientRectangle, 2));
            G.FillPath(gloss, DrawThunder.RoundRect(ClientRectangle, 2));
            G.FillPath(botbar, DrawThunder.RoundRect(R2, 1));
            G.FillPath(fill, DrawThunder.RoundRect(R3, 1));
            G.DrawPath(o, DrawThunder.RoundRect(ClientRectangle, 2));
            G.DrawPath(Pens.Black, DrawThunder.RoundRect(R4, 2));
            G.DrawString(Text, drawFont, new SolidBrush(Color.FromArgb(5, 5, 5)), R5, format);
            G.DrawString(Text, drawFont, new SolidBrush(ForeColor), R6, format);
 
            e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
            G.Dispose();
            B.Dispose();
        }
    }
 
    #endregion
}