国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#窗口實現定時關機系統

2020-01-24 00:02:07
字體:
來源:轉載
供稿:網友

本文實例為大家分享了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() + "秒";      }    }  }}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丰城市| 荔浦县| 五华县| 综艺| 宁明县| 射洪县| 宝山区| 卫辉市| 隆尧县| 通州市| 信阳市| 阜康市| 张掖市| 启东市| 来安县| 双峰县| 仁化县| 平塘县| 喜德县| 西宁市| 济南市| 托克逊县| 博爱县| 大城县| 博罗县| 多伦县| 个旧市| 文登市| 石林| 赫章县| 宣恩县| 秦皇岛市| 定陶县| 德兴市| 武邑县| 德安县| 屯门区| 共和县| 二连浩特市| 广水市| 贺州市|