I can get mouse co-ordinates when mouse is down and up as
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 I need the mouse co-ordinates continuously when mouse is down and move until mouse is up. I don't need co-ordinates when mouse move only but I need co-ordinates when mouse is down and move. How to do 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 am using isDragging true or false onmosueup and down but this just hang the application. Should I use timer or thread?
您需要处理MouseMove
并检查鼠标是否按下。
There are a few things you should do:
bool isDragging
isDragging = true
and this.Capture = true
isDragging = false
and this.Capture = false
if (isDragging)
and if it is true, respond as you wish. Your MouseMove handler will be supplied with the current mouse coords. The use of Capture
is important, because otherwise you can lose MouseMove and MouseUp messages.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.