C#窗口實(shí)現(xiàn)定時(shí)關(guān)機(jī)系統(tǒng)
本文實(shí)例為大家分享了C#窗口實(shí)現(xiàn)定時(shí)關(guān)機(jī)系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
看一下運(yùn)行之后的效果圖
看代碼
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("設(shè)定的定時(shí)時(shí)間必須大于當(dāng)前時(shí)間"); } 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 = "距離當(dāng)前關(guān)機(jī)還有" +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 = "距離當(dāng)前關(guān)機(jī)還有" + this.max.ToString() + "秒"; } } } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#實(shí)現(xiàn)協(xié)同過(guò)濾算法的實(shí)例代碼
這篇文章介紹了C#實(shí)現(xiàn)協(xié)同過(guò)濾算法的實(shí)例代碼,有需要的朋友可以參考一下2013-07-07C#實(shí)現(xiàn)較為實(shí)用的SQLhelper
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)較為實(shí)用SQLhelper的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10詳解C#用new和override來(lái)實(shí)現(xiàn)抽象類(lèi)的重寫(xiě)區(qū)別
本篇文章主要介紹了詳解C#用new和override來(lái)實(shí)現(xiàn)抽象類(lèi)的重寫(xiě)區(qū)別,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧。2017-02-02C#自定義繁體和簡(jiǎn)體字庫(kù)實(shí)現(xiàn)中文繁體和簡(jiǎn)體之間轉(zhuǎn)換的方法
這篇文章主要介紹了C#自定義繁體和簡(jiǎn)體字庫(kù)實(shí)現(xiàn)中文繁體和簡(jiǎn)體之間轉(zhuǎn)換的方法,通過(guò)自定義繁簡(jiǎn)轉(zhuǎn)換字庫(kù)實(shí)現(xiàn)繁體與簡(jiǎn)體轉(zhuǎn)換的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04C#特性 匿名類(lèi)型與隱式類(lèi)型局部變量使用介紹
這篇文章主要介紹了C#特性-匿名類(lèi)型與隱式類(lèi)型局部變量,需要的朋友可以參考下2014-12-12