-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsForm.cs
More file actions
58 lines (49 loc) · 2.01 KB
/
SettingsForm.cs
File metadata and controls
58 lines (49 loc) · 2.01 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
using System;
using System.Windows.Forms;
namespace WorkTimer
{
public partial class SettingsForm : Form
{
public AppSettings Settings { get; private set; }
public SettingsForm(AppSettings currentSettings)
{
InitializeComponent();
Settings = currentSettings;
txtIdleTime.Text = (Settings.IdleSecondsForPause / 60).ToString();
txtAutoResume.Text = (Settings.ManualPauseSecondsForAutoResume).ToString();
txtWpm.Text = Settings.WpmForFullMeter.ToString();
chkAlwaysOnTop.Checked = Settings.AlwaysOnTop;
trackBarOpacity.Value = (int)(Settings.Opacity * 100);
lblOpacity.Text = $"{trackBarOpacity.Value}%";
}
private void btnOk_Click(object sender, EventArgs e)
{
if (ValidateInputs())
{
Settings.IdleSecondsForPause = int.Parse(txtIdleTime.Text) * 60;
Settings.ManualPauseSecondsForAutoResume = int.Parse(txtAutoResume.Text);
Settings.WpmForFullMeter = int.Parse(txtWpm.Text);
Settings.AlwaysOnTop = chkAlwaysOnTop.Checked;
Settings.Opacity = trackBarOpacity.Value / 100.0;
this.DialogResult = DialogResult.OK;
this.Close();
}
}
private bool ValidateInputs()
{
bool valid = true;
valid &= int.TryParse(txtIdleTime.Text, out int idle) && idle >= 1;
valid &= int.TryParse(txtAutoResume.Text, out int resume) && resume >= 1;
valid &= int.TryParse(txtWpm.Text, out int wpm) && wpm >= 10;
if (!valid)
{
MessageBox.Show("Please enter valid positive numbers for all fields.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return valid;
}
private void trackBarOpacity_Scroll(object sender, EventArgs e)
{
lblOpacity.Text = $"{trackBarOpacity.Value}%";
}
}
}