startTime = DateTime.Now;
DispatcherTimer dt = new DispatcherTimer();
dt.Interval = new TimeSpan(0, 0, 1);
dt.Tick += new EventHandler(dt_Tick);//调用函数
dt.Start();
void dt_Tick(object sender, EventArgs e)
{
timeSpan = DateTime.Now.Subtract(startTime);
//用TimeSpan来格式化时间
timer1.Content = string.Format("{0:00}:{1:00}:{2:00}", (int)timeSpan.TotalHours,timeSpan.Minutes, timeSpan.Seconds);
//用DateTime来格式化时间
timer2.Content = String.Format("{0:HH:mm:ss}", new DateTime(timeSpan.Ticks));
}
最后
以上就是俊秀指甲油最近收集整理的关于C#中计时器的实现的全部内容,更多相关C#中计时器内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复