c# - Get mouse co-ordinates continuously while mouse move onmousedown -


i can mouse co-ordinates when mouse down ,

  private void panel2_mousedown(object sender, mouseeventargs e) {     mouseclickedx = e.x;     mouseclickedy = e.y; }     private void panel2_mouseup(object sender, mouseeventargs e) {     mousereleasex = e.x;     mousereleasey = e.y; } 

but need mouse co-ordinates continuously when mouse down , move until mouse up. don't need co-ordinates when mouse move need co-ordinates when mouse down , move. how that?

edit:

   private void panel2_mousemove(object sender, mouseeventargs e)         {             while (isdragging) {                 mousemovex = e.x;                 mousemovey = e.y;                 label1.text = mousemovex.tostring();                 label2.text = mousemovey.tostring();             }         } 

i using isdragging true or false onmosueup , down hang application. should use timer or thread?

there few things should do:

  1. add class private boolean field called bool isdragging
  2. in mousedown handler, set isdragging = true , this.capture = true
  3. in mouseup handler, set isdragging = false , this.capture = false
  4. add mousemove handler. in it, check if (isdragging) , if true, respond wish. mousemove handler supplied current mouse coords.

the use of capture important, because otherwise can lose mousemove , mouseup messages.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -