C# 如何为WPF创建计时器
我有一个C# 如何为WPF创建计时器,c#,wpf,button,C#,Wpf,Button,我有一个按钮\u单击事件和一个按钮\u预览鼠标左键向下事件。我想为我的按钮\u预览MouseLeftButtonDown事件设置计时器。如果用户的鼠标按下超过1秒,“我的代码”将执行按钮\u PreviewMouseLeftButtonDown事件。我如何才能做到这一点?您应该使用Dispatcher: using System.Windows.Threading; ... DispatcherTimer timer = new DispatcherTimer(); timer.Tick +=
按钮\u单击
事件和一个按钮\u预览鼠标左键向下
事件。我想为我的按钮\u预览MouseLeftButtonDown
事件设置计时器。如果用户的鼠标按下超过1秒,“我的代码”将执行按钮\u PreviewMouseLeftButtonDown
事件。我如何才能做到这一点?您应该使用Dispatcher:
using System.Windows.Threading;
...
DispatcherTimer timer = new DispatcherTimer();
timer.Tick += TimerTick;
timer.Interval = TimeSpan.FromSeconds(1);
timer.Start();
...
private void TimerTick(object sender, EventArgs e)
{
// Put some code here
}
您应该使用Dispatcher:
using System.Windows.Threading;
...
DispatcherTimer timer = new DispatcherTimer();
timer.Tick += TimerTick;
timer.Interval = TimeSpan.FromSeconds(1);
timer.Start();
...
private void TimerTick(object sender, EventArgs e)
{
// Put some code here
}
你好好。。。基本上,就像你说的。它完全是这样的:-)所以,如果它不到一秒钟,那么它应该只做按钮点击?嗨。。。。好。。。基本上,就像你说的。它完全是这样的:-)所以,如果它不到一秒钟,那么它应该只做按钮点击?