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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#region Imports
 
using DPumpHydr.WinFrmUI.RLT.Design.Metro;
using DPumpHydr.WinFrmUI.RLT.Enum.Metro;
using DPumpHydr.WinFrmUI.RLT.Extension.Metro;
using DPumpHydr.WinFrmUI.RLT.Interface.Metro;
using DPumpHydr.WinFrmUI.RLT.Manager;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
 
#endregion
 
namespace DPumpHydr.WinFrmUI.RLT.Controls
{
    #region MetroLinkLabel
 
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(MetroLinkLabel), "Bitmaps.LinkLabel.bmp")]
    [Designer(typeof(MetroLinkLabelDesigner))]
    [DefaultProperty("Text")]
    [ComVisible(true)]
    public class MetroLinkLabel : LinkLabel, IMetroControl
    {
        #region Interfaces
 
        [Category("Metro"), Description("Gets or sets the style associated with the control.")]
        public Style Style
        {
            get => StyleManager?.Style ?? _style;
            set
            {
                _style = value;
                switch (value)
                {
                    case Style.Light:
                        ApplyTheme();
                        break;
                    case Style.Dark:
                        ApplyTheme(Style.Dark);
                        break;
                    case Style.Custom:
                        ApplyTheme(Style.Custom);
                        break;
                    default:
                        ApplyTheme();
                        break;
                }
                Invalidate();
            }
        }
 
        [Category("Metro"), Description("Gets or sets the Style Manager associated with the control.")]
        public MetroStyleManager StyleManager
        {
            get => _styleManager;
            set { _styleManager = value; Invalidate(); }
        }
 
        [Category("Metro"), Description("Gets or sets the The Author name associated with the theme.")]
        public string ThemeAuthor { get; set; }
 
        [Category("Metro"), Description("Gets or sets the The Theme name associated with the theme.")]
        public string ThemeName { get; set; }
 
        #endregion Interfaces
 
        #region Global Vars
 
        private readonly Utilites _utl;
 
        #endregion Global Vars
 
        #region Internal Vars
 
        private Style _style;
        private MetroStyleManager _styleManager;
 
        private bool _isDerivedStyle = true;
 
        #endregion Internal Vars
 
        #region Constructors
 
        public MetroLinkLabel()
        {
            SetStyle
            (
                ControlStyles.ResizeRedraw |
                ControlStyles.OptimizedDoubleBuffer |
                ControlStyles.SupportsTransparentBackColor,
                    true
            );
            UpdateStyles();
            base.Font = MetroFonts.Light(10);
            base.Cursor = Cursors.Hand;
            _utl = new Utilites();
            _style = Style.Dark;
            ApplyTheme();
            LinkBehavior = LinkBehavior.HoverUnderline;
        }
 
        #endregion Constructors
 
        #region ApplyTheme
 
        private void ApplyTheme(Style style = Style.Light)
        {
            if (!IsDerivedStyle)
            {
                return;
            }
 
            switch (style)
            {
                case Style.Light:
                    ForeColor = Color.Black;
                    BackColor = Color.Transparent;
                    ActiveLinkColor = Color.FromArgb(85, 197, 245);
                    LinkColor = Color.FromArgb(65, 177, 225);
                    VisitedLinkColor = Color.FromArgb(45, 157, 205);
                    ThemeAuthor = "Taiizor";
                    ThemeName = "MetroLight";
                    UpdateProperties();
                    break;
                case Style.Dark:
                    ForeColor = Color.FromArgb(170, 170, 170);
                    BackColor = Color.Transparent;
                    ActiveLinkColor = Color.FromArgb(85, 197, 245);
                    LinkColor = Color.FromArgb(65, 177, 225);
                    VisitedLinkColor = Color.FromArgb(45, 157, 205);
                    ThemeAuthor = "Taiizor";
                    ThemeName = "MetroDark";
                    UpdateProperties();
                    break;
                case Style.Custom:
                    if (StyleManager != null)
                    {
                        foreach (System.Collections.Generic.KeyValuePair<string, object> varkey in StyleManager.LinkLabelDictionary)
                        {
                            switch (varkey.Key)
                            {
                                case "ForeColor":
                                    ForeColor = _utl.HexColor((string)varkey.Value);
                                    break;
                                case "BackColor":
                                    BackColor = _utl.HexColor((string)varkey.Value);
                                    break;
                                case "LinkColor":
                                    LinkColor = _utl.HexColor((string)varkey.Value);
                                    break;
                                case "ActiveLinkColor":
                                    ActiveLinkColor = _utl.HexColor((string)varkey.Value);
                                    break;
                                case "VisitedLinkColor":
                                    VisitedLinkColor = _utl.HexColor((string)varkey.Value);
                                    break;
                                case "LinkBehavior":
                                    switch ((string)varkey.Value)
                                    {
                                        case "HoverUnderline":
                                            LinkBehavior = LinkBehavior.HoverUnderline;
                                            break;
                                        case "AlwaysUnderline":
                                            LinkBehavior = LinkBehavior.AlwaysUnderline;
                                            break;
                                        case "NeverUnderline":
                                            LinkBehavior = LinkBehavior.NeverUnderline;
                                            break;
                                        case "SystemDefault":
                                            LinkBehavior = LinkBehavior.SystemDefault;
                                            break;
                                    }
                                    break;
 
                                default:
                                    return;
                            }
                        }
                    }
 
                    UpdateProperties();
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(style), style, null);
            }
        }
 
        private void UpdateProperties()
        {
            Invalidate();
        }
 
        #endregion ApplyTheme
 
        #region Events
 
        /*
            protected override void WndProc(ref Message m)
            {
                //_utl.SmoothCursor(ref m);
                _utl.SmoothCursor(ref m, base.Cursor);
                //_utl.NormalCursor(ref m, base.Cursor);
 
                base.WndProc(ref m);
            }
        */
 
        #endregion
 
        #region Properties
 
        [Category("Metro"), Description("Gets or sets the form forecolor.")]
        public override Color ForeColor { get; set; } = Color.Black;
 
        [Category("Metro"), Description("Gets or sets the form backcolor.")]
        public override Color BackColor { get; set; } = Color.Transparent;
 
        [Category("Metro"), Description("Gets or sets LinkColor used by the control.")]
        public new Color LinkColor { get; set; } = Color.FromArgb(65, 177, 225);
 
        [Category("Metro"), Description("Gets or sets ActiveLinkColor used by the control.")]
        public new Color ActiveLinkColor { get; set; } = Color.FromArgb(85, 197, 245);
 
        [Category("Metro"), Description("Gets or sets VisitedLinkColor used by the control.")]
        public new Color VisitedLinkColor { get; set; } = Color.FromArgb(45, 157, 205);
 
        [Category("Metro"), Description("Gets or sets LinkBehavior used by the control.")]
        public new LinkBehavior LinkBehavior { get; set; }
 
        [Category("Metro"), Description("Gets or sets DisabledLinkColor used by the control.")]
        public new Color DisabledLinkColor { get; set; } = Color.FromArgb(133, 133, 133);
 
        [Category("Metro")]
        [Description("Gets or sets the whether this control reflect to parent(s) style. \n " +
                     "Set it to false if you want the style of this control be independent. ")]
        public bool IsDerivedStyle
        {
            get => _isDerivedStyle;
            set
            {
                _isDerivedStyle = value;
                Refresh();
            }
        }
 
        #endregion Properties
    }
 
    #endregion
}