tangxu
2025-02-10 e40718947b5aa9205c87a7478aa86c37a82e0510
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
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Native;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Extension.Metro
{
    #region UtilitesExtension
 
    internal class Utilites
    {
        public static PathGradientBrush GlowBrush(Color CenterColor, Color SurroundColor, Point P, Rectangle Rect)
        {
            GraphicsPath GP = new() { FillMode = FillMode.Winding };
            GP.AddRectangle(Rect);
            return new PathGradientBrush(GP)
            {
                CenterColor = CenterColor,
                SurroundColors = new[] { SurroundColor },
                FocusScales = P
            };
        }
 
        public static SolidBrush SolidBrushRGBColor(int R, int G, int B, int A = 0)
        {
            return new SolidBrush(Color.FromArgb(A, R, G, B));
        }
 
        public SolidBrush SolidBrushHTMlColor(string C_WithoutHash)
        {
            return new SolidBrush(HexColor(C_WithoutHash));
        }
 
        public static Pen PenRGBColor(int red, int green, int blue, int alpha, float size)
        {
            return new(Color.FromArgb(alpha, red, green, blue), size);
        }
 
        public Pen PenHTMlColor(string colorWithoutHash, float size = 1)
        {
            return new(HexColor(colorWithoutHash), size);
        }
 
        public Color HexColor(string hexColor)
        {
            return ColorTranslator.FromHtml(hexColor);
        }
 
        public static Color GetAlphaHexColor(int alpha, string hexColor)
        {
            return Color.FromArgb(alpha, ColorTranslator.FromHtml(hexColor));
        }
 
        public void InitControlHandle(Control ctrl)
        {
            if (ctrl.IsHandleCreated)
            {
                return;
            }
 
            //IntPtr unused = ctrl.Handle;
            foreach (Control child in ctrl.Controls)
            {
                InitControlHandle(child);
            }
        }
 
        public void SmoothCursor(ref Message message)
        {
            if (message.Msg != User32.WM_SETCURSOR)
            {
                return;
            }
 
            User32.SetCursor(User32.LoadCursor(IntPtr.Zero, User32.IDC_HAND));
            message.Result = IntPtr.Zero;
        }
 
        public void SmoothCursor(ref Message message, Cursor Cursor)
        {
            if (message.Msg != User32.WM_SETCURSOR && Cursor != Cursors.Hand)
            {
                return;
            }
 
            User32.SetCursor(User32.LoadCursor(IntPtr.Zero, User32.IDC_HAND));
            message.Result = IntPtr.Zero;
        }
 
        public static void NormalCursor(ref Message message, Cursor Cursor)
        {
            if (message.Msg == User32.WM_SETCURSOR && Cursor == Cursors.Hand)
            {
                User32.SetCursor(User32.LoadCursor(IntPtr.Zero, User32.IDC_HAND));
                message.Result = IntPtr.Zero;
            }
        }
    }
 
    #endregion
}