110,539
社区成员
发帖
与我相关
我的任务
分享
protected override void OnFormClosing(FormClosingEventArgs e)
{
switch (e.CloseReason)
{
case CloseReason.ApplicationExitCall:
e.Cancel = true;
MessageBox.Show("拦截关闭要求事件!");
break;
case CloseReason.FormOwnerClosing:
e.Cancel = true;
MessageBox.Show("拦截自身关闭事件!");
break;
case CloseReason.MdiFormClosing:
e.Cancel = true;
MessageBox.Show("拦截MDI窗体关闭事件!");
break;
case CloseReason.None:
break;
case CloseReason.TaskManagerClosing:
e.Cancel = true;
MessageBox.Show("拦截任务管理器关闭事件!");
break;
case CloseReason.UserClosing:
e.Cancel = true;
MessageBox.Show("拦截用户关闭事件!");
break;
case CloseReason.WindowsShutDown:
e.Cancel = true;
MessageBox.Show("拦截关机事件!");
break;
default:
break;
}
base.OnFormClosing(e);
}
参见:http://www.cnblogs.com/ajiefj/archive/2010/05/11/1732419.html
Process myProcess = new Process();//定义一个线程实例;
myProcess.StartInfo.FileName = "cmd.exe";//启动名为"cmd.exe"的线程,就相当于你点击电脑左下角的"开机"-"运行"-输入cmd后回车,也就是启动了命令提示符界面;
myProcess.StartInfo.UseShellExecute = false;//关闭Shell的使用
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");//相当于你在命令提示符界面输入"shutdown -s -t 0"