C#窗口实现定时关机系统-创新互联

本文实例为大家分享了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)
    {

    }
  }
}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享文章:C#窗口实现定时关机系统-创新互联
链接分享:http://scjbc.cn/article/djpsce.html

其他资讯