using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace ShutDownComputer
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
t.Interval = 1000;
t.Tick+=new EventHandler(t_Tick);
t.Start();
}
Timer t = new Timer();
void t_Tick(object sender, EventArgs e)
{
labelNowTime.Text = DateTime.Now.ToString();
}
[DllImport("user32.dll", EntryPoint = "ExitWindowsEx", CharSet = CharSet.Ansi)]
private static extern int ExitWindowsEx(int uFlags,int dwReserved);
private void 注销ToolStripMenuItem_Click(object sender, EventArgs e)
{
ExitWindowsEx(0,0);
}
//定义关机方法
private void ShutDown()
{
Process myProcess = new Process();
myProcess.StartInfo.FileName = "";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start(); //启动进程
myProcess.StandardInput.WriteLine("shutdown -s -t 0");
}
//定义最小化方法
private void HideMainForm()
{
this.Hide();
}
//定义显示方法
private void ShowMainForm()
{
this.Show();
this.WindowState = FormWindowState.Normal;
this关机程序代码.Activate();
}
private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
{
ShutDown();//调用关机方法
}
private void 关机重启ToolStripMenuItem_Click(object sender, EventArgs e)
{
Process myProcess = new Process();
myProcess.StartInfo.FileName = "";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
myProcess.StandardInput.WriteLine("shutdown -r -t 0");
}
private void 退出程序ToolStripMenuItem1_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
private void 重新设定ToolStripMenuItem_Click(object sender, EventArgs e)
{
numericUpDownHour.Value = 1;
numericUpDownMinute.Value = 1;
numericUpDownSecond.Value = 30;
numericUpDownHour.Focus();
timer.Stop();
}
private void 计时开始ToolStripMenuItem_Click(object sender, EventArgs e)
{
timer.Interval = 1000;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
HideMainForm();
}
Timer timer = new Timer();
void timer_Tick(object sender, EventArgs e)
{
if (numericUpDownSecond.Value == 0)
{
if (numericUpDownMinute.Value == 0)
{
if (numericUpDownHour.Value == 0)
{
timer.Stop();
ShutDown();
}
else
{
numericUpDownHour.Value--;
numericUpDownMinute.Value = 60;
}
}
else
{
numericUpDownMinute.Value--;
numericUpDownSecond.Value = 59;
}
}
else
{
numericUpDownSecond.Value--;
}
}
private void 版本信息ToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("软件名称:定时关机工具\n开发环境:Microsoft Visual Studio 2010\n版本号:H4GRG68X82 (*^__^*)……");
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论