C#窗口实现定时关机系统
本文实例为大家分享了C#窗口实现定时关机系统的具体代码,供大家参考,具体内容如下
看一下运行之后的效果图
看代码
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; namespace ShutDoneWindows { public partial class ShutDone : Form { public ShutDone() { InitializeComponent(); } private void menuItemExit_Click(object sender, EventArgs e) { Application.Exit(); } private void ShutDone_Load(object sender, EventArgs e) { this.timer1.Start(); DateTime DT = System.DateTime.Now; string dt = System.DateTime.Now.ToString(); txtDatatime.Text = dt; } private void btnHide_Click(object sender, EventArgs e) { this.Hide(); this.notifyIcon1.Visible = true; } private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { this.Visible = true; this.WindowState = FormWindowState.Normal; this.notifyIcon1.Visible = false; } private void btnShutDone_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("cmd.exe", "/cshutdown -s -t 0"); } private void btnReLogin_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("cmd.exe", "/logoff 0"); } private void btnReBoot_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("cmd.exe", "/shutdown -r 0"); } private void timer1_Tick(object sender, EventArgs e) { DateTime objDatetime = System.DateTime.Now; string cData = objDatetime.ToLongDateString(); string cTime = objDatetime.ToLongTimeString(); this.txtDatatime.Text = cData + "" + cTime; if (this.chkStrat.Checked == true) { int Y = this.dtpCurrentDate.Value.Year; int M = this.dtpCurrentDate.Value.Month; int D = this.dtpCurrentDate.Value.Day; int H = this.dtpCurrentTime.Value.Hour; int Min = this.dtpCurrentTime.Value.Minute; int S = this.dtpCurrentTime.Value.Second; objDatetime = new DateTime(Y, M, D, H, Min, S); System.TimeSpan remain = objDatetime - System.DateTime.Now; double time = remain.TotalSeconds; if (time < 0) { this.chkStrat.Checked = false; MessageBox.Show("设定的定时时间必须大于当前时间"); } else { if (time < 60 && this.rbtnOneMinute.Checked == true) { AwokeForm aw = new AwokeForm(); this.timer1.Stop(); this.Hide(); aw.Show(); } if (time < 0 && this.rbtnNone.Checked == true) { System.Diagnostics.Process.Start("cmd.exe", "/cshutdown -s -t 0"); } } } } private void chkStrat_CheckedChanged(object sender, EventArgs e) { } private void rbtnOneMinute_CheckedChanged(object sender, EventArgs e) { } private void rbtnNone_CheckedChanged(object sender, EventArgs e) { } } }
窗口提醒的代码!
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; namespace ShutDoneWindows { public partial class AwokeForm : Form { public AwokeForm() { InitializeComponent(); } private void btnCancel_Click(object sender, EventArgs e) { timer1.Stop(); this.Close(); } private void AwokeForm_Load(object sender, EventArgs e) { this.timer1.Start(); this.lblMessage.Text = "距离当前关机还有" +60+ "秒"; } int max = 60; private void timer1_Tick(object sender, EventArgs e) { this.max = max - 1; if (this.max == 0) { System.Diagnostics.Process.Start("cmd.exe", "/cshutdown -s -t 0"); this.timer1.Stop(); } else { this.lblMessage.Text = "距离当前关机还有" + this.max.ToString() + "秒"; } } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
上一篇:C#实现倒计时关闭提示框功能
栏 目:C#教程
本文标题:C#窗口实现定时关机系统
本文地址:https://www.xiuzhanwang.com/a1/C_jiaocheng/4705.html
您可能感兴趣的文章
- 01-10C#实现txt定位指定行完整实例
- 01-10WinForm实现仿视频播放器左下角滚动新闻效果的方法
- 01-10C#实现清空回收站的方法
- 01-10C#实现读取注册表监控当前操作系统已安装软件变化的方法
- 01-10C#实现多线程下载文件的方法
- 01-10C#实现Winform中打开网页页面的方法
- 01-10C#实现远程关闭计算机或重启计算机的方法
- 01-10C#自定义签名章实现方法
- 01-10C#文件断点续传实现方法
- 01-10winform实现创建最前端窗体的方法
阅读排行
本栏相关
- 01-10C#通过反射获取当前工程中所有窗体并
- 01-10关于ASP网页无法打开的解决方案
- 01-10WinForm限制窗体不能移到屏幕外的方法
- 01-10WinForm绘制圆角的方法
- 01-10C#实现txt定位指定行完整实例
- 01-10WinForm实现仿视频播放器左下角滚动新
- 01-10C#停止线程的方法
- 01-10C#实现清空回收站的方法
- 01-10C#通过重写Panel改变边框颜色与宽度的
- 01-10C#实现读取注册表监控当前操作系统已
随机阅读
- 01-10delphi制作wav文件的方法
- 08-05DEDE织梦data目录下的sessions文件夹有什
- 08-05织梦dedecms什么时候用栏目交叉功能?
- 01-10SublimeText编译C开发环境设置
- 01-10使用C语言求解扑克牌的顺子及n个骰子
- 04-02jquery与jsp,用jquery
- 01-11Mac OSX 打开原生自带读写NTFS功能(图文
- 08-05dedecms(织梦)副栏目数量限制代码修改
- 01-11ajax实现页面的局部加载
- 01-10C#中split用法实例总结