如何设置定时器事件处理程序? [英] How to set timer in an event handler?
本文介绍了如何设置定时器事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在建立一个应用程序,我想,当我点击一个特定的按钮计时器才开始。
Am currently building an app and I want the timer to start only when I click a particular button.
所以,反正是有一次,按钮被点击开始计时? (我不希望计时器在页面加载尽快启动)
So is there anyway to start timer once a button is clicked? (I don't want the timer to start as soon as the page loads)
推荐答案
勾选此的帖子。
//Inside Page Load
System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();
dt.Interval = new TimeSpan(0, 0, 0, 0, 500); // 500 Milliseconds
dt.Tick += new EventHandler(dt_Tick);
Tick事件处理程序为您的计时器
Tick Event Handler for your timer
void dt_Tick(object sender, EventArgs e)
{
// Do Stuff here.
}
现在你的按钮单击事件处理程序,你会做
Now on your button click event handler you will do
dt.Start();
希望这有助于。
Hope this helps.
这篇关于如何设置定时器事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文