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)文章
WinForm自定義函數(shù)FindControl實(shí)現(xiàn)按名稱(chēng)查找控件
這篇文章主要介紹了WinForm自定義函數(shù)FindControl實(shí)現(xiàn)按名稱(chēng)查找控件,需要的朋友可以參考下2014-08-08
C#?Winform文本面板帶滾動(dòng)條的實(shí)現(xiàn)過(guò)程
當(dāng)數(shù)據(jù)過(guò)多時(shí),往往無(wú)法在一頁(yè)中展示,所以非常需要一個(gè)滾動(dòng)條來(lái)調(diào)節(jié)頁(yè)面內(nèi)容,這篇文章主要給大家介紹了關(guān)于C#?Winform文本面板帶滾動(dòng)條的實(shí)現(xiàn)過(guò)程,需要的朋友可以參考下2022-12-12
總結(jié)C#網(wǎng)絡(luò)編程中對(duì)于Cookie的設(shè)定要點(diǎn)
這篇文章主要介紹了總結(jié)C#網(wǎng)絡(luò)編程中對(duì)于Cookie的設(shè)定要點(diǎn),文中還給出了一個(gè)cookie操作實(shí)例僅供參照,需要的朋友可以參考下2016-04-04
C#科學(xué)繪圖之使用scottPlot繪制多個(gè)圖像
ScottPlot是基于.Net的一款開(kāi)源免費(fèi)的交互式可視化庫(kù),支持Winform和WPF等UI框架,本文主要為大家詳細(xì)介紹了如何使用scottPlot實(shí)現(xiàn)繪制多個(gè)圖像,需要的可以參考下2023-12-12
Unity實(shí)現(xiàn)場(chǎng)景加載功能
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)場(chǎng)景加載,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10
C#實(shí)現(xiàn)遞歸調(diào)用的Lambda表達(dá)式
這篇文章介紹了C#實(shí)現(xiàn)遞歸調(diào)用的Lambda表達(dá)式,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06

