码迷,mamicode.com
首页 > Windows程序 > 详细

WinForm中Timer倒计时

时间:2014-05-16 05:22:31      阅读:446      评论:0      收藏:0      [点我收藏+]

标签:winform   style   blog   class   code   c   

添加一个Timer控件:

在初始化代码中

bubuko.com,布布扣
       public Form1()
        {
            InitializeComponent();
            button_Read.Enabled = false;
            button_Start.Enabled = false;
            timer1.Enabled = true;
            timer1.Interval = 1000;
            timer1.Start();
        }
bubuko.com,布布扣

双击Timer控件,在其事件中

bubuko.com,布布扣
  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;
                    }
                }
            }
        }
bubuko.com,布布扣

 

WinForm中Timer倒计时,布布扣,bubuko.com

WinForm中Timer倒计时

标签:winform   style   blog   class   code   c   

原文地址:http://www.cnblogs.com/kennyliu/p/3726453.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!