-
-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathCustomTheme.cs
More file actions
140 lines (121 loc) · 4.17 KB
/
CustomTheme.cs
File metadata and controls
140 lines (121 loc) · 4.17 KB
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
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace XrmToolBox.Extensibility
{
public class CustomTheme
{
private static CustomTheme theme;
public CustomTheme()
{
}
public static CustomTheme Instance
{
get
{
if (theme == null)
{
theme = new CustomTheme();
}
return theme;
}
}
public Color Background1 { get; protected set; }
public Color Background2 { get; protected set; }
public Color Background3 { get; protected set; }
public Color Background4 { get; protected set; }
public Color Background5 { get; protected set; }
public Color ForeColor1 { get; protected set; }
public Color ForeColor2 { get; protected set; }
public Color ForeColor3 { get; protected set; }
public Color ForeColor4 { get; protected set; }
public Color ForeColor5 { get; protected set; }
public Color HighlightColor { get; protected set; }
public bool IsActive { get; private set; }
public ProfessionalColorTable MenuColorTable { get; protected set; }
public void ApplyTheme(Control control)
{
if (!IsActive) return;
UpdateChildControlsTheme(control);
foreach (var ts in control.Controls.OfType<ToolStrip>())
{
ts.Renderer = new ToolStripProfessionalRenderer(MenuColorTable);
UpdateDropdownItemsTheme(ts.Items);
}
}
public void SetTheme(CustomTheme customTheme)
{
theme = customTheme;
theme.IsActive = customTheme != null;
}
private void UpdateChildControlsTheme(Control control)
{
control.ForeColor = ForeColor1;
control.BackColor = Background1;
if (control is TextBox
|| control is ComboBox
|| control is RichTextBox
)
{
control.BackColor = Background2;
control.ForeColor = ForeColor2;
}
else if (control is LinkLabel ll)
{
ll.ActiveLinkColor = HighlightColor;
ll.DisabledLinkColor = ForeColor5;
ll.ForeColor = HighlightColor;
ll.LinkColor = HighlightColor;
}
else if (control is Button b)
{
if (b.FlatAppearance.BorderSize > 0)
{
b.BackColor = Background2;
b.ForeColor = ForeColor2;
b.FlatStyle = FlatStyle.Flat;
}
}
if (control is TextBox tb)
{
tb.BorderStyle = BorderStyle.FixedSingle;
}
if (control is RichTextBox rtb && rtb.ReadOnly)
{
control.BackColor = Background1;
control.ForeColor = ForeColor1;
}
foreach (Control childControl in control.Controls)
{
UpdateChildControlsTheme(childControl);
}
}
private void UpdateDropdownItemsTheme(ToolStripItemCollection items)
{
foreach (ToolStripItem item in items)
{
item.ForeColor = ForeColor1;
item.BackColor = Background1;
if (item is ToolStripMenuItem tsmi)
{
UpdateDropdownItemsTheme(tsmi.DropDownItems);
}
if (item is ToolStripTextBox tstb)
{
tstb.TextBox.BackColor = Background2;
tstb.TextBox.ForeColor = ForeColor2;
}
if (item is ToolStripComboBox tstc)
{
tstc.ComboBox.BackColor = Background2;
tstc.ComboBox.ForeColor = ForeColor2;
}
if (item is ToolStripDropDownButton tsddb)
{
UpdateDropdownItemsTheme(tsddb.DropDownItems);
}
}
}
}
}