-
C#教程之C#窗口实现定时关机系统(2)
本站最新发布 C#从入门到精通
试听地址 https://www.xin3721.com/eschool/CSharpxin3721/
本文实例为大家分享了C#窗口实现定时关机系统的具体代码,供大家参考,具体内容如下
试听地址 https://www.xin3721.com/eschool/CSharpxin3721/
本文实例为大家分享了C#窗口实现定时关机系统的具体代码,供大家参考,具体内容如下
看一下运行之后的效果图
看代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
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) { } } } |
窗口提醒的代码!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
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# 面向对象
假设客车的座位数是9行4列,使用二维数
C#基于接口设计三层架构Unity篇
C#线程 入门
C#读取静态类常量属性和值
C# 插件式编程
C# 委托与事件有啥区别?
C#队列学习笔记:队列(Queue)和堆栈(Stack
linq 多表分组左连接查询查询统计
C#队列学习笔记:MSMQ入门一
C# 在Word中添加Latex 数学公式和符号
inncheck命令 – 检查语法
基于UDP的服务器端和客户端
再谈UDP和TCP
在socket编程中使用域名
网络数据传输时的大小端问题
socket编程实现文件传输功能
如何优雅地断开TCP连接?
图解TCP四次握手断开连接
详细分析TCP数据的传输过程
SqlServer 利用游标批量更新数据
BOS只读状态修改
SQL Server等待事件—PAGEIOLATCH_EX
数据库多行转换为单一列
获取数据表最后最后访问,修改,更新,
计算经历的时间
SQL查询结果自定义排序
修改数据库默认位置
日期简单加或减
从日期获取年,月或日