C#窗口实现定时关机系统
- 作者: 新疆-塔城市-李哥
- 来源: 51数据库
- 2020-08-06
这篇文章主要为大家详细介绍了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#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
热点文章
团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
0
使用 MSBuild.exe 在发布模式下构建 C# 解决方案
0
当我发布 Web 应用程序时,AfterPublish 脚本不运行
0
构建时 T4 转换的产品仅在下一个构建中使用
0
ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
0
新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
0
如何将条件编译符号(DefineConstants)传递给 msbuild
0
MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
0
NuGet 包还原找不到包,没有源
0
使用 C# 6.0 功能运行 TFS 构建
0
