How to catch the Mouse Hold event on the control?

I want to catch an event that a user clicks and holds with a mouse on a control in C #.

I read on MSDN and I only see Mouse Down, Mouse Up, ... events, but don't have Move Hold events.

+4
source share
2 answers

You need to use certain events with some timer in between.

Example:

  • Mousedown
    • Start timer
  • Mouseup
    • Disable timer

In case the user holds more timer time - call the event handler when mouseUp accelerates and then the timer expires - disable the running timer.

+5
source

First, you must use a stopwatch to determine the time you want.

using System.Diagnostics; 

Second, define a global instance of the 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 in millisecond if (s.ElapsedMilliseconds <= 700 && s.ElapsedMilliseconds >= 200) { //you code here. } s.Reset(); } 
-1
source

Source: https://habr.com/ru/post/1434136/


All Articles