当鼠标向下和向上时,我可以获得鼠标坐标
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;
}
但是当鼠标停止时我需要连续鼠标坐标并移动直到鼠标向上移动。鼠标移动时我不需要坐标,但是当鼠标停下来移动时我需要坐标。怎么做?
修改
private void panel2_MouseMove(object sender, MouseEventArgs e)
{
while (isDragging) {
mouseMoveX = e.X;
mouseMoveY = e.Y;
label1.Text = mouseMoveX.ToString();
label2.Text = mouseMoveY.ToString();
}
}
我正在使用isDragging true或false onmosueup and down但这只是挂起应用程序。我应该使用计时器还是线程?
答案 0 :(得分:3)
您需要处理MouseMove
并检查鼠标是否已关闭。
答案 1 :(得分:2)
你应该做一些事情:
bool isDragging
isDragging = true
和this.Capture = true
isDragging = false
和this.Capture = false
if (isDragging)
,如果是,请按您的意愿回复。您的MouseMove处理程序将随当前的鼠标坐标一起提供。使用Capture
很重要,否则您可能会丢失MouseMove和MouseUp消息。