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:
- add class private boolean field called
bool isdragging
- in mousedown handler, set
isdragging = true
,this.capture = true
- in mouseup handler, set
isdragging = false
,this.capture = false
- 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
Post a Comment