tangxu
2024-10-22 7a0d1efa4784d176a32f182ecae671711e98ca92
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
#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.Forms
{
    #region ThunderForm
 
    public class ThunderForm : ContainerControl
    {
        public Image Image { get; set; } = Properties.Resources.AppImage;
        public Color BodyColorA { get; set; } = Color.FromArgb(25, 25, 25);
        public Color BodyColorB { get; set; } = Color.FromArgb(30, 35, 48);
        public Color BodyColorC { get; set; } = Color.FromArgb(46, 46, 46);
        public Color BodyColorD { get; set; } = Color.FromArgb(50, 55, 58);
 
        public ThunderForm()
        {
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.UserPaint, true);
            ForeColor = Color.WhiteSmoke;
            Padding = new Padding(11, 29, 11, 6);
            MinimumSize = new(270, 50);
            DoubleBuffered = true;
        }
 
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);
            Refresh();
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            Bitmap B = new(Width, Height);
            Graphics G = Graphics.FromImage(B);
            Rectangle TopLeft = new(0, 0, Width - 125, 28);
            Rectangle TopRight = new(Width - 82, 0, 81, 28);
            Rectangle Body = new(10, 10, Width - 21, Height - 16);
            Rectangle Body2 = new(5, 5, Width - 11, Height - 6);
            base.OnPaint(e);
            LinearGradientBrush BodyBrush = new(Body2, BodyColorA, BodyColorB, 90);
            LinearGradientBrush BodyBrush2 = new(Body, BodyColorC, BodyColorD, 120);
            LinearGradientBrush gloss = new(new Rectangle(0, 0, Width - 128, 28 / 2), Color.FromArgb(240, Color.FromArgb(26, 26, 26)), Color.FromArgb(5, 255, 255, 255), 90);
            LinearGradientBrush gloss2 = new(new Rectangle(Width - 82, 0, Width - 205, 28 / 2), Color.FromArgb(240, Color.FromArgb(26, 26, 26)), Color.FromArgb(5, 255, 255, 255), 90);
            LinearGradientBrush mainbrush1 = new(TopLeft, Color.FromArgb(26, 26, 26), Color.FromArgb(30, 30, 30), 90);
            LinearGradientBrush mainbrush2 = new(TopRight, Color.FromArgb(26, 26, 26), Color.FromArgb(30, 30, 30), 90);
            Pen P1 = new(Color.FromArgb(174, 195, 30), 2);
            Font drawFont = new("Tahoma", 10, FontStyle.Bold);
 
            G.Clear(Color.Fuchsia);
            G.FillPath(BodyBrush, DrawThunder.RoundRect(Body2, 3));
            G.DrawPath(Pens.Black, DrawThunder.RoundRect(Body2, 3));
 
            G.FillPath(BodyBrush2, DrawThunder.RoundRect(Body, 3));
            G.DrawPath(Pens.Black, DrawThunder.RoundRect(Body, 3));
 
            G.FillPath(mainbrush1, DrawThunder.RoundRect(TopLeft, 3));
            G.FillPath(gloss, DrawThunder.RoundRect(TopLeft, 3));
            G.DrawPath(Pens.Black, DrawThunder.RoundRect(TopLeft, 3));
 
            G.FillPath(mainbrush2, DrawThunder.RoundRect(TopRight, 3));
            G.FillPath(gloss2, DrawThunder.RoundRect(TopRight, 3));
            G.DrawPath(Pens.Black, DrawThunder.RoundRect(TopRight, 3));
 
            if (Image == null)
            {
                G.DrawLine(P1, 14, 9, 14, 22);
                G.DrawLine(P1, 17, 6, 17, 25);
                G.DrawLine(P1, 20, 9, 20, 22);
                G.DrawLine(P1, 11, 12, 11, 19);
                G.DrawLine(P1, 23, 12, 23, 19);
                G.DrawLine(P1, 8, 14, 8, 17);
                G.DrawLine(P1, 26, 14, 26, 17);
                G.DrawString(base.Text, drawFont, new SolidBrush(ForeColor), new Rectangle(32, 1, Width - 1, 27), new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center });
            }
            else
            {
                G.DrawImage(Image, 11, 2, 25, 25);
                G.DrawString(base.Text, drawFont, new SolidBrush(ForeColor), new Rectangle(45, 1, Width - 1, 27), new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center });
            }
 
            e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
 
            G.Dispose();
            B.Dispose();
        }
 
        private Point MouseP = new(0, 0);
        private bool cap = false;
        private readonly int moveheight = 29;
 
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (e.Button == MouseButtons.Left && new Rectangle(0, 0, Width, moveheight).Contains(e.Location))
            {
                cap = true;
                MouseP = e.Location;
            }
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            cap = false;
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (cap)
            {
                Point p = new()
                {
                    X = MousePosition.X - MouseP.X,
                    Y = MousePosition.Y - MouseP.Y
                };
                Parent.Location = p;
            }
        }
        protected override void OnCreateControl()
        {
            base.OnCreateControl();
            ParentForm.FormBorderStyle = FormBorderStyle.None;
            ParentForm.TransparencyKey = Color.Fuchsia;
            Dock = DockStyle.Fill;
        }
    }
 
    #endregion
}