public FormWDT() { InitializeComponent(); dh.lost_countChanged += lost_countChanged; dh.kill += runCmd; dh.kill += onRunKillCmd; dh.cancelKill += runCmd; dh.printMsg += showMsgOnStatusBar; dh.printMsg += logMsg; // load settings DH_DESC saved_desc; if (Properties.Settings.Default.saved) { saved_desc = new DH_DESC(Properties.Settings.Default.period, Properties.Settings.Default.max_count, Properties.Settings.Default.target_IP, Properties.Settings.Default.cmd, Properties.Settings.Default.cmd_abort); } else { saved_desc = new DH_DESC(); } dh.ApplyConfig(saved_desc); textBoxPeroid.Text = saved_desc.period.ToString(); textBoxMaxCount.Text = saved_desc.max_count.ToString(); textBoxIP.Text = saved_desc.target_IP; textBoxCmd.Text = saved_desc.cmd; textBoxCmdAbort.Text = saved_desc.cmd_abort; buttonApply.Enabled = false; }
public void ApplyConfig(DH_DESC desc) { if (desc.period > 0 && desc.max_count > 0) { this.desc = desc; timer.Interval = desc.period * 1000; // ms timer.Start(); } }
private void buttonApply_Click(object sender, EventArgs e) { try { double period = Convert.ToDouble(textBoxPeroid.Text); int max_count = Convert.ToInt32(textBoxMaxCount.Text); DH_DESC desc = new DH_DESC(period, max_count, textBoxIP.Text.Trim(), textBoxCmd.Text, textBoxCmdAbort.Text); dh.ApplyConfig(desc); saveSettings(desc); buttonApply.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "错误"); } }
private void saveSettings(DH_DESC desc) { Properties.Settings.Default.period = desc.period; Properties.Settings.Default.max_count = desc.max_count; Properties.Settings.Default.target_IP = desc.target_IP; Properties.Settings.Default.cmd = desc.cmd; Properties.Settings.Default.cmd_abort = desc.cmd_abort; Properties.Settings.Default.saved = true; Properties.Settings.Default.Save(); }
private void buttonDefault_Click(object sender, EventArgs e) { if (MessageBox.Show("确实要恢复到默认设置?", "重置", MessageBoxButtons.YesNo) == DialogResult.Yes) { DH_DESC default_desc = new DH_DESC(); dh.ApplyConfig(default_desc); saveSettings(default_desc); textBoxPeroid.Text = default_desc.period.ToString(); textBoxMaxCount.Text = default_desc.max_count.ToString(); textBoxIP.Text = default_desc.target_IP; textBoxCmd.Text = default_desc.cmd; textBoxCmdAbort.Text = default_desc.cmd_abort; } }