C#窗口實現(xiàn)定時關機系統(tǒng)
更新時間:2019年07月30日 10:48:23 作者:mq_shouhug753951mq
這篇文章主要為大家詳細介紹了C#窗口實現(xiàn)定時關機系統(tǒng),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C#窗口實現(xiàn)定時關機系統(tǒng)的具體代碼,供大家參考,具體內容如下
看一下運行之后的效果圖

看代碼
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#用new和override來實現(xiàn)抽象類的重寫區(qū)別
本篇文章主要介紹了詳解C#用new和override來實現(xiàn)抽象類的重寫區(qū)別,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧。2017-02-02
C#自定義繁體和簡體字庫實現(xiàn)中文繁體和簡體之間轉換的方法
這篇文章主要介紹了C#自定義繁體和簡體字庫實現(xiàn)中文繁體和簡體之間轉換的方法,通過自定義繁簡轉換字庫實現(xiàn)繁體與簡體轉換的技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04

