Form1.cs
上传用户:tomsong001
上传日期:2022-03-19
资源大小:31k
文件大小:2k
- 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;
- using System.Runtime.InteropServices;
- namespace AutoShutdown
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- DateTime t;
- private void btShutdown_Click(object sender, EventArgs e)
- {
- TimeSpan tp;
- TimeSpan.TryParse(textTime.Text, out tp);
- this.Text = tp.ToString();
- t = DateTime.Now + tp;
- timer1.Enabled = true;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- textTime.Text = "00:50:00";
- }
- internal const int EWX_SHUTDOWN = 0x00000001;
- internal const int EWX_REBOOT = 0x00000002;
- internal const int EWX_FORCE = 0x00000004;
- [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
- internal static extern bool ExitWindowsEx(int flg, int rea);
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (t> DateTime.Now)
- {
- TimeSpan dt = t - DateTime.Now;
- this.label1.Text = (dt).ToString();
- }
- else
- {
- timer1.Enabled = false;
- WindowsExit.PowerOff();
- this.label1.Text = "";
- }
- }
- }
- }