服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C# - C#窗口实现定时关机系统

C#窗口实现定时关机系统

2022-07-31 11:26mq_shouhug753951mq C#

这篇文章主要为大家详细介绍了C#窗口实现定时关机系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了C#窗口实现定时关机系统的具体代码,供大家参考,具体内容如下

看一下运行之后的效果图

C#窗口实现定时关机系统

看代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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)
    {
 
    }
  }
}

窗口提醒的代码!

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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() + "秒";
      }
    }
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/mq_shouhug753951mq/article/details/48296227

延伸 · 阅读

精彩推荐
  • C#C#中TCP粘包问题的解决方法

    C#中TCP粘包问题的解决方法

    这篇文章主要为大家详细介绍了C#中TCP粘包问题的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    白云随风5672022-01-17
  • C#深入理解C# 装箱和拆箱(整理篇)

    深入理解C# 装箱和拆箱(整理篇)

    通过装箱和拆箱操作,能够在值类型和引用类型中架起一做桥梁.换言之,可以轻松的实现值类型与引用类型的互相转换...

    幸福安康3862022-01-19
  • C#C#和Java有什么区别和联系

    C#和Java有什么区别和联系

    这篇文章主要介绍了C#和Java有什么区别和联系的相关资料,本文介绍的非常详细,涉及到rsa语法,c#和java互转方面的知识点,非常不错,具有参考借鉴价值,...

    一只LowCoder8312021-12-01
  • C#C#使用FileStream循环读取大文件数据的方法示例

    C#使用FileStream循环读取大文件数据的方法示例

    这篇文章主要介绍了C#使用FileStream循环读取大文件数据的方法,结合实例形式分析了FileStream文件流的形式循环读取大文件的相关操作技巧,需要的朋友可以参...

    番兄9462022-01-04
  • C#C#实现绑定DataGridView与TextBox之间关联的方法

    C#实现绑定DataGridView与TextBox之间关联的方法

    这篇文章主要介绍了C#实现绑定DataGridView与TextBox之间关联的方法,涉及C#绑定控件关联性的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下...

    我心依旧6212021-10-20
  • C#C#获取客户端相关信息实例总结

    C#获取客户端相关信息实例总结

    这篇文章主要介绍了C#获取客户端相关信息的方法,以实例形式总结了C#获取客户端IP地址、网络连接、硬件信息等相关技巧,具有一定参考借鉴价值,需要的朋...

    C#教程网9612021-10-27
  • C#C#与Java的MD5简单验证(实例代码)

    C#与Java的MD5简单验证(实例代码)

    下面小编就为大家带来一篇C#与Java的MD5简单验证(实例代码)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    C#教程网7482021-12-07
  • C#c#单例模式(Singleton)的6种实现

    c#单例模式(Singleton)的6种实现

    这篇文章主要介绍了c#单例模式(Singleton)的6种实现 ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    rush3602021-12-15