forked from EFLFE/PingoMeter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetting.cs
131 lines (114 loc) · 4.12 KB
/
Setting.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Diagnostics;
using System.Net;
using System.Windows.Forms;
namespace PingoMeter
{
public partial class Setting : Form
{
public Setting()
{
InitializeComponent();
SyncFromConfig();
labelVersion.Text = "Version " + Program.VERSION;
toolTip1.SetToolTip(numbersModeCheckBox, "Use numbers for the ping instead of a graph.");
}
private void SyncToConfig(IPAddress address)
{
Config.SetAll(
delay: (int)delay.Value,
maxPing: (int)maxPing.Value,
bgColor: setBgColor.BackColor,
goodColor: setGoodColor.BackColor,
normalColor: setNormalColor.BackColor,
badColor: setBadColor.BackColor,
runOnStartup: false,
address: address,
alarmConnectionLost: alarmConnectionLost.Checked,
alarmTimeOut: alarmTimeOut.Checked,
alarmResumed: alarmResumed.Checked,
useNumbers: numbersModeCheckBox.Checked);
}
private void SyncFromConfig()
{
delay.Value = Config.Delay;
maxPing.Value = Config.MaxPing;
setBgColor.BackColor = Config.BgColor.Color;
setGoodColor.BackColor = Config.GoodColor.Color;
setNormalColor.BackColor = Config.NormalColor.Color;
setBadColor.BackColor = Config.BadColor.Color;
alarmTimeOut.Checked = Config.AlarmTimeOut;
alarmConnectionLost.Checked = Config.AlarmConnectionLost;
alarmResumed.Checked = Config.AlarmResumed;
numbersModeCheckBox.Checked = Config.UseNumbers;
//isStartUp.Checked = Config.s_runOnStartup;
if (Config.TheIPAddress != null)
ipAddress.Text = Config.TheIPAddress.ToString();
}
private void SetBgColor_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
setBgColor.BackColor = colorDialog1.Color;
}
}
private void SetGoodColor_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
setGoodColor.BackColor = colorDialog1.Color;
}
}
private void SetNormalColor_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
setNormalColor.BackColor = colorDialog1.Color;
}
}
private void SetBadColor_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
setBadColor.BackColor = colorDialog1.Color;
}
}
private void Apply_Click(object sender, EventArgs e)
{
// check ip address
if (!IPAddress.TryParse(ipAddress.Text, out IPAddress address))
{
MessageBox.Show("IP Address is invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
SyncToConfig(address);
Config.Save();
Close();
}
private void Cancel_Click(object sender, EventArgs e)
{
Close();
}
private void Reset_Click(object sender, EventArgs e)
{
if (MessageBox.Show(
"Reset all settings to default?",
"Reset all?",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
== DialogResult.Yes)
{
Config.Reset();
SyncFromConfig();
}
}
private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://github.com/EFLFE/PingoMeter");
}
private void numbersModeCheckBox_CheckedChanged(object sender, EventArgs e)
{
graphColorsGroupBox.Visible = !numbersModeCheckBox.Checked;
}
}
}