C#小工具 ---- 倒计时自动关机小工具

上图

C#小工具 ---- 倒计时自动关机小工具

public partial class Form1 : Form
    {
        private DateTime StartTime;
        private const int hours = 0;
        private const int minutes = 30;
        private const int sec = 0;
        private TimeSpan sCountdown = new TimeSpan(hours, minutes, sec);

        private bool FromStatus = false;
        
        public Form1()
        {
            InitializeComponent();
            this.Size = new Size(525, 260);
            this.tableLayoutPanel1.Height = 135;
        }
        private void CenterFrom()
        {
            this.Hide();
            this.Size = new Size(525, 260);
            this.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - this.Width)/2, (Screen.PrimaryScreen.WorkingArea.Height - this.Height)/2);
            lableTip.Visible = true;
            label6.Text = "↗";
            this.Show();
        }

        private void TopFrom()
        {
            this.Hide();
            this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, 0);
            this.Size = new Size(525, 130);
            lableTip.Visible = false;
            label6.Text = "↙";
            this.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            TimeSpan end = DateTime.Now.Subtract(StartTime);
            TimeSpan cd = sCountdown - end;
            if(cd.TotalSeconds<0)
            {
                timer1.Stop();
                Process.Start("c:/windows/system32/shutdown.exe", "-s -t 0");
                this.Hide();
            }
            else
                Showtime(cd);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(132, 132,132);
            this.TransparencyKey = Color.FromArgb(132, 132, 132);
            lableTip.Text = "关机倒计时";
            Showtime(sCountdown);
            StartTime = DateTime.Now;
            timer1.Start();
        }
        private void Showtime(TimeSpan cd)
        {
            label1.Text = (cd.Minutes / 10).ToString();
            label2.Text = (cd.Minutes % 10).ToString();
            label3.Text = (cd.Seconds / 10).ToString();
            label4.Text = (cd.Seconds % 10).ToString();
        }
        

        private void label6_Click(object sender, EventArgs e)
        {
            if (FromStatus)
                CenterFrom();
            else
                TopFrom();
            FromStatus = !FromStatus;
        }
    }

 

C#小工具 ---- 倒计时自动关机小工具C#小工具 ---- 倒计时自动关机小工具 陇东 发布了10 篇原创文章 · 获赞 5 · 访问量 1003 私信 关注
上一篇:1033 旧键盘打字


下一篇:TypeScript 定义函数的几种写法