zoukankan      html  css  js  c++  java
  • WinForm中Timer倒计时

    添加一个Timer控件:

    在初始化代码中

           public Form1()
            {
                InitializeComponent();
                button_Read.Enabled = false;
                button_Start.Enabled = false;
                timer1.Enabled = true;
                timer1.Interval = 1000;
                timer1.Start();
            }

    双击Timer控件,在其事件中

      private void timer1_Tick(object sender, EventArgs e)
            {
                string time = button_Read.Text;
                string[] arr = time.Split(':');
                if (arr.Length == 2)
                {
                    int min, second;
                    if (int.TryParse(arr[0], out min) && int.TryParse(arr[1], out second))
                    {
                        second--;
                        if (second < 0)
                        {
                            second = 59;
                            min--;
                        }
                        button_Read.Text = min + ":" + second;
                        button_Start.Text = min + ":" + second;
    
                        if (min ==0 && second ==0 )
                        {
                            button_Read.Text = "读取ini.txt";
                            button_Start.Text = "开始测试";
                            button_Read.Enabled = true;
                            button_Start.Enabled = true;
                        }
                    }
                }
            }
  • 相关阅读:
    day21继承
    day22
    面向对象
    常用模块
    模块
    迭代器
    【游记】2020-CSP
    【初赛解析】2021CSP-S初赛解析(不完全)
    【题解】AcWing 1390.通电围栏
    【题解】AcWing 1387.家的范围
  • 原文地址:https://www.cnblogs.com/kennyliu/p/3726453.html
Copyright © 2011-2022 走看看