winform 计时和倒计时

计时:

        private static DateTime Dtime; 

        private static TimeSpan TimeCount = new TimeSpan();

private void btnInterferogramSet_Click(object sender, EventArgs e)

        {

            Dtime = DateTime.Now;

        }

private void timer_Tick(object sender, EventArgs e)

        {

            TimeCount = DateTime.Now - Dtime;

            lb222.Text = string.Format("{0:00}:{1:00}:{2:00}", TimeCount.Hours, TimeCount.Minutes, TimeCount.Seconds);

        }

倒计时:

 private static DateTime Dtime;

        private static TimeSpan TimeCount = new TimeSpan();

private void btnInterferogramSet_Click(object sender, EventArgs e)

        {

            Dtime = DateTime.Now.AddMinutes(6);

        }

private void timer_Tick(object sender, EventArgs e)

        {

            TimeCount = Dtime - DateTime.Now ;

            lb222.Text = string.Format("{0:00}:{1:00}:{2:00}", TimeCount.Hours, TimeCount.Minutes, TimeCount.Seconds);

        }

你可能感兴趣的:(winform 计时和倒计时)