0

I have a button_click event and a button_PreviewMouseLeftButtonDown event. I want to set a timer for my button_PreviewMouseLeftButtonDown event. If the user's mouse is down for more than 1 second, then my code executes the button_PreviewMouseLeftButtonDown event. How can I accomplish this?

Joel
  • 1,564
  • 7
  • 12
  • 20
CZA
  • 35
  • 1
  • 8

1 Answers1

4

You should use a DispatcherTimer:

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
}
Clemens
  • 123,504
  • 12
  • 155
  • 268
Smaiil
  • 139
  • 1
  • 5