C#窗口实现定时关机系统
程序员文章站
2023-02-14 21:38:50
本文实例为大家分享了c#窗口实现定时关机系统的具体代码,供大家参考,具体内容如下
看一下运行之后的效果图
看代码
using system;
u...
本文实例为大家分享了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#用timer实现背单词小程序