-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptionsForm.cs
114 lines (104 loc) · 4.08 KB
/
OptionsForm.cs
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
using System;
using System.Configuration;
using System.Windows.Forms;
using System.Drawing;
namespace DavidVidmar.WindowsFader
{
/// <summary>
/// Screen saver option form.
/// </summary>
internal partial class OptionsForm : Form
{
/// <summary>
/// Initializes a new instance of the <see cref="OptionsForm"/> class.
/// </summary>
public OptionsForm()
{
this.InitializeComponent();
this.completeInTextBox.Text = Settings.CompleteFadeInSeconds.ToString();
this.endOpacityTrackBar.Value = Convert.ToInt32(Settings.EndOpacityPercent * 100);
this.endOpacityTextBox.Text = this.endOpacityTrackBar.Value.ToString();
this.colorPanel.BackColor = Color.FromArgb(Settings.FadeColor);
}
/// <summary>
/// Applies the changes.
/// </summary>
private void ApplyChanges()
{
int completeInValue;
try
{
completeInValue = Convert.ToInt32(this.completeInTextBox.Text);
if (completeInValue < 1) completeInValue = 1;
if (completeInValue > 10000) completeInValue = 180;
}
catch
{
MessageBox.Show("Enter value in seconds!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Settings.CompleteFadeInSeconds = completeInValue;
Settings.EndOpacityPercent = this.endOpacityTrackBar.Value / 100.0;
Settings.FadeColor = this.colorPanel.BackColor.ToArgb();
}
/// <summary>
/// Handles the Click event of the btnOK control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void ButtonOkClicked(object sender, EventArgs e)
{
try
{
this.ApplyChanges();
}
catch (ConfigurationException)
{
MessageBox.Show("Your settings couldn't be saved. Make sure that you have a .config file in the same directory as your screensaver.", "Failed to Save Settings", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Close();
}
}
/// <summary>
/// Handles the Click event of the btnCancel control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void ButtonCancelClicked(object sender, EventArgs e)
{
Close();
}
/// <summary>
/// Handles the Scroll event of the endOpacityTrackBar control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void EndOpacityTrackBarScroll(object sender, EventArgs e)
{
endOpacityTextBox.Text = endOpacityTrackBar.Value.ToString();
}
/// <summary>
/// Handles the Click event of the colorPanel control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
private void ColorPanelClicked(object sender, EventArgs e)
{
if (colorDialog.ShowDialog() == DialogResult.OK)
{
colorPanel.BackColor = colorDialog.Color;
}
}
/// <summary>
/// Sets the default fade color to black.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Forms.LinkLabelLinkClickedEventArgs"/> instance containing the event data.</param>
private void DefaultColorLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
colorPanel.BackColor = Color.Black;
}
}
}