yangyin
2025-03-27 b0de14c2670b9ff0079dacfb4b7457b438368f11
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
#region Imports
 
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Forms
{
    #region DreamForm
 
    public class DreamForm : GroupBox
    {
        private int _TitleHeight = 25;
        public int TitleHeight
        {
            get => _TitleHeight;
            set
            {
                if (value > Height)
                {
                    value = Height;
                }
 
                if (value < 2)
                {
                    Height = 1;
                }
 
                _TitleHeight = value;
                Invalidate();
            }
        }
 
        private HorizontalAlignment _TitleAlign = (HorizontalAlignment)2;
        public HorizontalAlignment TitleAlign
        {
            get => _TitleAlign;
            set
            {
                _TitleAlign = value;
                Invalidate();
            }
        }
 
        protected override void OnHandleCreated(EventArgs e)
        {
            Dock = (DockStyle)5;
            if (Parent.GetType() == typeof(Form))
            {//.FormBorderStyle = 0;
             //(ParentForm)Parent;
                FindForm().FormBorderStyle = 0;
                //Convert.ChangeType(Parent, typeof(Form));
            }
 
            base.OnHandleCreated(e);
        }
 
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (new Rectangle(Parent.Location.X, Parent.Location.Y, Width - 1, _TitleHeight - 1).IntersectsWith(new Rectangle(MousePosition.X, MousePosition.Y, 1, 1)))
            {
                Capture = false;
                //Message  M = Message.Create(Parent.Handle, 161, 2, 0);
                Message M = Message.Create(Parent.Handle, 161, (IntPtr)2, (IntPtr)0);
                //DefWndProc(M);
                DefWndProc(ref M);
            }
            base.OnMouseDown(e);
        }
 
        public Color ColorA { get; set; } = Color.FromArgb(40, 218, 255);
        public Color ColorB { get; set; } = Color.FromArgb(63, 63, 63);
        public Color ColorC { get; set; } = Color.FromArgb(41, 41, 41);
        public Color ColorD { get; set; } = Color.FromArgb(27, 27, 27);
        public Color ColorE { get; set; } = Color.FromArgb(0, 0, 0, 0);
        public Color ColorF { get; set; } = Color.FromArgb(25, 255, 255, 255);
 
 
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            //
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            using Bitmap B = new(Width, Height);
            using Graphics G = Graphics.FromImage(B);
            G.Clear(ColorC);
 
            //Draw.Gradient(G, _ColorD, _ColorC, 0, 0, Width, _TitleHeight)
 
            SizeF S = G.MeasureString(Text + "1", Font);
            float O = 6;
            if (_TitleAlign == (HorizontalAlignment)2)
            {
                O = (Width / 2) - (S.Width / 2);
            }
 
            if (_TitleAlign == (HorizontalAlignment)1)
            {
                O = Width - S.Width - 6;
            }
 
            Rectangle R = new((int)O, ((_TitleHeight + 2) / 2) - ((int)S.Height / 2), (int)S.Width, (int)S.Height);
            using (Brush T = new LinearGradientBrush(R, ColorA, ColorC, LinearGradientMode.Vertical))
            {
                G.DrawString(Text, Font, T, R);
            }
 
            G.DrawLine(new(ColorC), 0, 1, Width, 1);
 
            // Draw.Blend(G, _ColorE, _ColorF, _ColorE, 0.5, 0, 0, _TitleHeight + 1, Width, 1)
            ColorBlend x = new();
            Color[] temp = { ColorE, ColorF, ColorE };
            x.Colors = temp;
            float[] temp2 = { 0.5F, 0, 0, _TitleHeight + 1, Width, 1 };
            x.Positions = temp2;
 
            /*
                LinearGradientBrush B = new(new Point(10, 110), new Point(140, 110), Color.White, Color.Black);
                B.InterpolationColors = C_Blend;
            */
 
            G.DrawLine(new(ColorD), 0, _TitleHeight, Width, _TitleHeight);
            G.DrawRectangle(new(ColorD), 0, 0, Width - 1, Height - 1);
            Bitmap B1 = B;
            e.Graphics.DrawImage(B, 0, 0);
        }
    }
 
    #endregion
}