I want to catch the event that user clicks and holds mouse on a control in C#.
I have read on MSDN and I only see events Mouse Down, Mouse Up, ... but don't have Move Hold event.
I want to catch the event that user clicks and holds mouse on a control in C#.
I have read on MSDN and I only see events Mouse Down, Mouse Up, ... but don't have Move Hold event.
You need to use mentinoed events with some timer between them.
Example:
In case if user holds more then timer time - invoke your event handler, when mouseUp happend faster then timer elapsed - disable runned timer.
First, you should use stop watch to detect time you want.
using System.Diagnostics;
Second, define a global instance of stopwatch class.
Stopwatch s = new Stopwatch();
This is the first event you should use:
private void controlName_MouseDown(object sender, MouseEventArgs e)
{
s.Start();
}
This is the second event you should use:
private void controlName_MouseUp(object sender, MouseEventArgs e)
{
s.Stop();
//determine time you want . but take attention it's in millisecond
if (s.ElapsedMilliseconds <= 700 && s.ElapsedMilliseconds >= 200)
{
//you code here.
}
s.Reset();
}