/// <summary> /// 保存设置 /// </summary> private void Button2_Click(object sender, EventArgs e) { Regedit.Save("Software\\tty228\\udp_turn_off", "countdown", textBox1.Text); Regedit.Save("Software\\tty228\\udp_turn_off", "port", textBox2.Text); Regedit.Save("Software\\tty228\\udp_turn_off", "msg", textBox3.Text); switch (comboBox1.Text) { case "关机": 关机ToolStripMenuItem_Click(null, null); break; case "休眠": 休眠ToolStripMenuItem_Click(null, null); break; case "睡眠": 睡眠ToolStripMenuItem_Click(null, null); break; case "锁定": 锁定ToolStripMenuItem_Click(null, null); break; default: 关机ToolStripMenuItem_Click(null, null); break; } if (checkBox1.Checked != 开机启动ToolStripMenuItem.Checked) { 开机启动ToolStripMenuItem_Click(null, null); } Application.Restart(); }
private void 锁定ToolStripMenuItem_Click(object sender, EventArgs e) { 关机ToolStripMenuItem.Checked = false; 休眠ToolStripMenuItem.Checked = false; 睡眠ToolStripMenuItem.Checked = false; 锁定ToolStripMenuItem.Checked = true; comboBox1.Text = "锁定"; Regedit.Save("Software\\tty228\\udp_turn_off", "Shutdown_Options", "LockWorkStation"); }
private void Form1_Load(object sender, EventArgs e) { Icon = Properties.Resources._001; notifyIcon1.Icon = Properties.Resources._001; this.BeginInvoke(new Action(() => { this.Hide(); this.Opacity = 1; }));//隐藏窗口并透明化 //初始化设置 if (Regedit.Read("Software\\tty228\\udp_turn_off", "countdown") == "" || Regedit.Read("Software\\tty228\\udp_turn_off", "port") == "" || Regedit.Read("Software\\tty228\\udp_turn_off", "msg") == "" || Regedit.Read("Software\\tty228\\udp_turn_off", "Shutdown_Options") == "") { Button1_Click(null, null); } else { textBox1.Text = Regedit.Read("Software\\tty228\\udp_turn_off", "countdown"); textBox2.Text = Regedit.Read("Software\\tty228\\udp_turn_off", "port"); textBox3.Text = Regedit.Read("Software\\tty228\\udp_turn_off", "msg"); switch (Regedit.Read("Software\\tty228\\udp_turn_off", "Shutdown_Options")) { case "shutdown": 关机ToolStripMenuItem_Click(null, null); break; case "dormancy": 休眠ToolStripMenuItem_Click(null, null); break; case "sleep": 睡眠ToolStripMenuItem_Click(null, null); break; case "LockWorkStation": 锁定ToolStripMenuItem_Click(null, null); break; default: 关机ToolStripMenuItem_Click(null, null); break; } if (Regedit.Read("Software\\Microsoft\\Windows\\CurrentVersion\\Run", "udp_turn_off") == "") { checkBox1.Checked = false; 开机启动ToolStripMenuItem.Checked = false; } else { checkBox1.Checked = true; 开机启动ToolStripMenuItem.Checked = true; } } Thread recvThread = new Thread(RecvMsg); recvThread.IsBackground = true; recvThread.Start(); SystemEvents.PowerModeChanged += OnPowerChange; //监听电源改变事件 Pc_online(); }
private void 开机启动ToolStripMenuItem_Click(object sender, EventArgs e) { if (开机启动ToolStripMenuItem.Checked == false) { checkBox1.Checked = true; 开机启动ToolStripMenuItem.Checked = true; Regedit.Save("Software\\Microsoft\\Windows\\CurrentVersion\\Run", "udp_turn_off", Process.GetCurrentProcess().MainModule.FileName); } else { checkBox1.Checked = false; 开机启动ToolStripMenuItem.Checked = false; Regedit.Delete("Software\\Microsoft\\Windows\\CurrentVersion\\Run", "udp_turn_off"); } }