-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.Theme.cs
More file actions
130 lines (115 loc) · 3.75 KB
/
Copy pathForm1.Theme.cs
File metadata and controls
130 lines (115 loc) · 3.75 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
namespace GroupDynamic;
public partial class Form1
{
private AppTheme currentTheme = AppTheme.System;
private void ApplyTheme(AppTheme theme)
{
currentTheme = theme;
appSettings.Theme = theme;
ThemeColors colors = ThemeService.GetColors(theme);
BackColor = colors.FormBackColor;
ForeColor = colors.ForeColor;
menuStrip1.BackColor = colors.PanelBackColor;
menuStrip1.ForeColor = colors.ForeColor;
topPanel.BackColor = colors.PanelBackColor;
topPanel.ForeColor = colors.ForeColor;
statusStrip1.BackColor = colors.PanelBackColor;
statusStrip1.ForeColor = colors.ForeColor;
searchTextBox.BackColor = colors.InputBackColor;
searchTextBox.ForeColor = colors.ForeColor;
searchLabel.ForeColor = colors.ForeColor;
ApplyThemeToControl(topPanel);
ApplyThemeToControl(menuStrip1);
ApplyThemeToControl(statusStrip1);
foreach (TabPage tabPage in documentTabControl.TabPages)
{
ApplyThemeToTab(tabPage);
}
lightThemeToolStripMenuItem.Checked = theme == AppTheme.Light;
darkThemeToolStripMenuItem.Checked = theme == AppTheme.Dark;
systemThemeToolStripMenuItem.Checked = theme == AppTheme.System;
}
private void ApplyThemeToTab(TabPage tabPage)
{
ThemeColors colors = ThemeService.GetColors(currentTheme);
tabPage.BackColor = colors.EditorBackColor;
tabPage.ForeColor = colors.ForeColor;
foreach (Control control in tabPage.Controls)
{
ApplyThemeToControl(control);
}
}
private void ApplyThemeToControl(Control control)
{
ThemeColors colors = ThemeService.GetColors(currentTheme);
if (control is RichTextBox richTextBox)
{
richTextBox.BackColor = colors.EditorBackColor;
richTextBox.ForeColor = colors.ForeColor;
return;
}
if (control is TextBox textBox)
{
textBox.BackColor = colors.InputBackColor;
textBox.ForeColor = colors.ForeColor;
}
else if (control is Button button)
{
button.BackColor = colors.ButtonBackColor;
button.ForeColor = colors.ForeColor;
button.FlatStyle = FlatStyle.Flat;
}
else
{
control.BackColor = colors.PanelBackColor;
control.ForeColor = colors.ForeColor;
}
foreach (Control child in control.Controls)
{
ApplyThemeToControl(child);
}
}
}
public static class ThemeService
{
public static ThemeColors GetColors(AppTheme theme)
{
return theme switch
{
AppTheme.Light => new ThemeColors(
Color.White,
Color.FromArgb(245, 245, 245),
Color.White,
Color.White,
Color.FromArgb(235, 235, 235),
Color.Black),
AppTheme.Dark => new ThemeColors(
Color.FromArgb(30, 31, 34),
Color.FromArgb(43, 45, 48),
Color.FromArgb(30, 31, 34),
Color.FromArgb(60, 63, 65),
Color.FromArgb(76, 80, 82),
Color.Gainsboro),
_ => new ThemeColors(
SystemColors.Control,
SystemColors.ControlLight,
Color.White,
Color.White,
SystemColors.Control,
SystemColors.ControlText)
};
}
}
public enum AppTheme
{
Light,
Dark,
System
}
public readonly record struct ThemeColors(
Color FormBackColor,
Color PanelBackColor,
Color EditorBackColor,
Color InputBackColor,
Color ButtonBackColor,
Color ForeColor);