日期:2014-05-17  浏览次数:21345 次

c# winform timer计时器停止并重置计时器

       最近在做一个倒计时的计时器,是用timer控件进行控制的。倒计时的部分是没有问题的,但是现在需要实现点击btn后,停止当前的计时,并且重置计时器为计时的初始状态这项功能。详见代码。
      

      
        private void btn_end_Click(object sender, EventArgs e)
        {
            timer1.Stop();
            timer1.Enabled = false;
            timer1.Dispose();
        }

        long sec = 1800;
        private void timer1_Tick(object sender, EventArgs e)
        {
            
            sec -= 1;
            this.lb_time.Text= new DateTime(sec * 1000000).ToLongTimeString();
            if (sec == 300 )
            {
               
                this.lb_zff.Text  = "最后30秒!";
                
               
                this.axWindowsMediaPlayer1.URL = "D:\\ding.wav";
            }
           
            if (sec == 0)
            {
                timer1.Stop();
                this.lb_zff.Text = "时间到!";
                this.axWindowsMediaPlayer1.URL= "D:\\ling.wav";

            }

              private void btn_start_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled)
            {
                timer1.Stop();
           
            }
            else
            {