-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettings.cs
More file actions
188 lines (165 loc) · 6.84 KB
/
Settings.cs
File metadata and controls
188 lines (165 loc) · 6.84 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
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
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using TimeWidget.Utils;
namespace TimeWidget
{
public partial class Settings : Form
{
readonly Form1 form1;
public Settings(Form1 owner)
{
form1 = owner;
InitializeComponent();
colorDialog1.FullOpen = true;
comboBox1.Text = "24 часовой";
comboBoxFonts.Text = form1.labelTime.Font.Name;
}
private void Settings_Load(object sender, EventArgs e)
{
label1.Text = $"BZH Studio © 2020 - {DateTime.Now.Year}";
BackColor = Color.FromArgb(255, 29, 29, 29);
IEnumerable<Label> labels = Controls.OfType<Label>().Where(x => x.Name.StartsWith("label"));
foreach (var label in labels)
{
label.BackColor = Color.FromArgb(255, 29, 29, 29);
label.ForeColor = Color.FromArgb(0, 255, 255, 255);
}
IEnumerable<Button> buttons = Controls.OfType<Button>().Where(x => x.Name.StartsWith("button"));
foreach (var button in buttons)
{
button.BackColor = Color.FromArgb(255, 29, 29, 29);
button.ForeColor = Color.FromArgb(0, 255, 255, 255);
}
IEnumerable<ComboBox> comboBoxes = Controls.OfType<ComboBox>().Where(x => x.Name.StartsWith("comboBox"));
foreach (var comboBox in comboBoxes)
{
comboBox.BackColor = Color.FromArgb(255, 29, 29, 29);
comboBox.ForeColor = Color.FromArgb(0, 255, 255, 255);
}
IEnumerable<CheckBox> checkBoxes = Controls.OfType<CheckBox>().Where(x => x.Name.StartsWith("checkBox"));
foreach (var checkBox in checkBoxes)
{
checkBox.BackColor = Color.FromArgb(255, 29, 29, 29);
checkBox.ForeColor = Color.FromArgb(0, 255, 255, 255);
}
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\TimeWidget", true))
{
bool topMost = key?.GetValue("TopMost")?.ToString() == "True";
if (topMost)
{
checkBoxTopMost.Checked = true;
}
else
{
checkBoxTopMost.Checked = false;
}
bool runWithWindows = key?.GetValue("RunWithWindows")?.ToString() == "True";
if (runWithWindows)
{
checkBoxRunWithWindows.Checked = true;
}
else
{
checkBoxRunWithWindows.Checked = false;
}
}
foreach (FontFamily font in FontFamily.Families)
{
comboBoxFonts.Items.Add(font.Name.ToString());
}
}
private void checkBoxTopMost_CheckedChanged(object sender, EventArgs e)
{
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\TimeWidget", true))
{
if (checkBoxTopMost.Checked)
{
form1.TopMost = true;
key.SetValue("TopMost", true);
}
else
{
form1.TopMost = false;
key.SetValue("TopMost", false);
}
}
}
private void ButtonWidgetColor_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.Cancel) return;
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\TimeWidget", true))
{
key.SetValue("BackgroundColor", ColorTranslator.ToWin32(Color.FromArgb(colorDialog1.Color.ToArgb())));
form1.BackColor = colorDialog1.Color;
form1.labelTime.BackColor = colorDialog1.Color;
}
}
private void ButtonTextColor_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.Cancel) return;
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\TimeWidget", true))
{
var textColor = key?.GetValue("TextColor");
form1.labelTime.ForeColor = ColorTranslator.FromWin32((int)textColor);
key.SetValue("TextColor", ColorTranslator.ToWin32(Color.FromArgb(colorDialog1.Color.A, colorDialog1.Color.R, colorDialog1.Color.G, colorDialog1.Color.B)));
form1.labelTime.ForeColor = colorDialog1.Color;
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// object selectedItem = comboBox1.SelectedItem;
// form1.hms = selectedItem.ToString();
string standartTime = "HH:mm:ss";
string twelveTime = "hh:mm:ss";
string NotSecTime12 = "hh:mm";
string NotSecTime24 = "HH:mm";
if (comboBox1.SelectedItem.ToString() == "24 часовой")
{
form1.hms = standartTime;
}
else if (comboBox1.SelectedItem.ToString() == "12 часовой")
{
form1.hms = twelveTime;
}
else if (comboBox1.SelectedItem.ToString() == "Без секунд (12)")
{
form1.hms = NotSecTime12;
}
else if (comboBox1.SelectedItem.ToString() == "Без секунд (24)")
{
form1.hms = NotSecTime24;
}
}
private void comboBoxFonts_SelectedIndexChanged(object sender, EventArgs e)
{
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\TimeWidget", true))
{
key.SetValue("Font", comboBoxFonts.Text);
form1.labelTime.Font = new Font(comboBoxFonts.Text, form1.labelTime.Font.Size);
}
}
private void checkBoxRunWithWindows_CheckedChanged(object sender, EventArgs e)
{
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\TimeWidget", true))
{
using (RegistryKey keyrun = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true))
{
if (checkBoxRunWithWindows.Checked)
{
key.SetValue("RunWithWindows", true);
keyrun.SetValue("TimeWidget", Application.ExecutablePath);
}
else
{
key.SetValue("RunWithWindows", false);
keyrun.DeleteValue("TimeWidget", false);
}
}
}
}
}
}