private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (sure) { PWD pwd = new PWD(); if (pwd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { MessageBox.Show("要输入授权码才能操作!"); sure = false; e.Cancel = true; return; } if (MessageBox.Show("确定要退出报警工具吗?", "退出提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { notifyIcon1.Dispose(); Environment.Exit(0); } else { sure = false; e.Cancel = true; } } else { e.Cancel = true; this.Hide(); this.ShowInTaskbar = false; } }
private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (!fault) { PWD pwd = new PWD(); if (pwd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { MessageBox.Show("要输入授权码才能操作!"); fault = true; checkBox1.Checked = !checkBox1.Checked; fault = false; return; } string keyValue = Application.ExecutablePath; if (checkBox1.Checked) { if (!IsExistKey(KeyName)) { WriteKey(KeyName, keyValue); } } else { DeleteKey(KeyName); } } }
private bool EnableAlarm(object o) { PWD pwd = new PWD(); if (pwd.ShowDialog() != System.Windows.Forms.DialogResult.OK) { MessageBox.Show("要输入授权码才能操作!"); return(false); } if (o is CheckBox) { CheckBox cb = o as CheckBox; if (cb.Checked) { timer1.Start(); 启用声音报警ToolStripMenuItem.Text = "禁用声音报警"; } else { timer1.Stop(); 启用声音报警ToolStripMenuItem.Text = "启用声音报警"; } } else if (o is ToolStripMenuItem) { ToolStripMenuItem t = o as ToolStripMenuItem; if (t.Text == "启用声音报警") { timer1.Start(); button1.Text = t.Text = "禁用声音报警"; } else { timer1.Stop(); button1.Text = t.Text = "启用声音报警"; } } return(true); }