Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何为WPF创建计时器_C#_Wpf_Button - Fatal编程技术网

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
}

你好好。。。基本上,就像你说的。它完全是这样的:-)所以,如果它不到一秒钟,那么它应该只做按钮点击?嗨。。。。好。。。基本上,就像你说的。它完全是这样的:-)所以,如果它不到一秒钟,那么它应该只做按钮点击?