-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsDialog.cs
More file actions
190 lines (162 loc) · 5.26 KB
/
SettingsDialog.cs
File metadata and controls
190 lines (162 loc) · 5.26 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
189
190
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace MeasuringStick;
public class SettingsDialog : Form
{
private readonly AppSettings _settings;
private TextBox _folderTextBox = null!;
private CheckBox _copyClipboardCheck = null!;
private CheckBox _showNotificationCheck = null!;
private CheckBox _autoSaveCheck = null!;
private TrackBar _opacityTrack = null!;
private Label _opacityLabel = null!;
public SettingsDialog(AppSettings settings)
{
_settings = settings;
InitializeComponents();
LoadSettings();
}
private void InitializeComponents()
{
this.Text = "Measuring Stick Settings";
this.Size = new Size(450, 320);
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.StartPosition = FormStartPosition.CenterScreen;
this.BackColor = Color.White;
int y = 20;
// Screenshot folder
var folderLabel = new Label
{
Text = "Screenshot Save Location:",
Location = new Point(20, y),
AutoSize = true
};
this.Controls.Add(folderLabel);
y += 25;
_folderTextBox = new TextBox
{
Location = new Point(20, y),
Size = new Size(300, 23),
ReadOnly = true
};
this.Controls.Add(_folderTextBox);
var browseButton = new Button
{
Text = "Browse...",
Location = new Point(330, y - 1),
Size = new Size(80, 25)
};
browseButton.Click += OnBrowseClick;
this.Controls.Add(browseButton);
y += 40;
// Opacity
var opacityTitleLabel = new Label
{
Text = "Element Opacity:",
Location = new Point(20, y),
AutoSize = true
};
this.Controls.Add(opacityTitleLabel);
_opacityLabel = new Label
{
Text = "100%",
Location = new Point(130, y),
AutoSize = true
};
this.Controls.Add(_opacityLabel);
y += 25;
_opacityTrack = new TrackBar
{
Location = new Point(20, y),
Size = new Size(390, 45),
Minimum = 10,
Maximum = 100,
TickFrequency = 10,
LargeChange = 10,
SmallChange = 10
};
_opacityTrack.ValueChanged += (s, e) => _opacityLabel.Text = $"{_opacityTrack.Value}%";
this.Controls.Add(_opacityTrack);
y += 50;
// Checkboxes
_copyClipboardCheck = new CheckBox
{
Text = "Copy screenshots to clipboard",
Location = new Point(20, y),
AutoSize = true
};
this.Controls.Add(_copyClipboardCheck);
y += 30;
_showNotificationCheck = new CheckBox
{
Text = "Show notification after saving screenshot",
Location = new Point(20, y),
AutoSize = true
};
this.Controls.Add(_showNotificationCheck);
y += 30;
_autoSaveCheck = new CheckBox
{
Text = "Auto-save screenshot on close (Measure + Screenshot mode)",
Location = new Point(20, y),
AutoSize = true
};
this.Controls.Add(_autoSaveCheck);
y += 40;
// Buttons
var saveButton = new Button
{
Text = "Save",
Location = new Point(230, y),
Size = new Size(80, 30),
DialogResult = DialogResult.OK
};
saveButton.Click += OnSaveClick;
this.Controls.Add(saveButton);
var cancelButton = new Button
{
Text = "Cancel",
Location = new Point(320, y),
Size = new Size(80, 30),
DialogResult = DialogResult.Cancel
};
this.Controls.Add(cancelButton);
this.AcceptButton = saveButton;
this.CancelButton = cancelButton;
}
private void LoadSettings()
{
_folderTextBox.Text = _settings.ScreenshotFolder;
_opacityTrack.Value = Math.Max(10, Math.Min(100, (int)(_settings.Opacity * 100)));
_opacityLabel.Text = $"{_opacityTrack.Value}%";
_copyClipboardCheck.Checked = _settings.CopyToClipboard;
_showNotificationCheck.Checked = _settings.ShowNotification;
_autoSaveCheck.Checked = _settings.AutoSaveScreenshot;
}
private void OnBrowseClick(object? sender, EventArgs e)
{
using var dialog = new FolderBrowserDialog
{
Description = "Select screenshot save location",
SelectedPath = _settings.ScreenshotFolder,
ShowNewFolderButton = true
};
if (dialog.ShowDialog() == DialogResult.OK)
{
_folderTextBox.Text = dialog.SelectedPath;
}
}
private void OnSaveClick(object? sender, EventArgs e)
{
_settings.ScreenshotFolder = _folderTextBox.Text;
_settings.Opacity = _opacityTrack.Value / 100.0;
_settings.CopyToClipboard = _copyClipboardCheck.Checked;
_settings.ShowNotification = _showNotificationCheck.Checked;
_settings.AutoSaveScreenshot = _autoSaveCheck.Checked;
_settings.Save();
}
}