c# 如何记录鼠标按下和松开这两个事件的鼠标位置?

来源:百度知道 编辑:UC知道 时间:2024/06/04 16:56:14
就是像鼠标拖动问题,需要获取鼠标按下和松开事件发生时的鼠标位置。请问怎么办?

Point p;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
p = new Point(e.X, e.Y); //按下
}

private void Form1_MouseUp(object sender, MouseEventArgs e)
{
p = new Point(e.X, e.Y); //松开
}

int x, y;

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
x = e.X;
y = e.Y;
}

private void Form1_MouseUp(object sender, MouseEventArgs e)
{
MessageBox.Show("鼠标按下坐标:" + x + "," + y + "\n鼠标释放坐标:" + e.X + "," + e.Y);
}