winForm 中怎么获取鼠标的移动方向?

来源:百度知道 编辑:UC知道 时间:2024/06/03 03:25:12
就是鼠标移动时 怎么判断他是向哪个方向移动的 上下左右..

在MouseMove事件中写以下代码
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
NotifyMouseMove(e.Location);
_LastPoint = e.Location;
}
private Point _LastPoint=new Point(0,0);
以下写展示鼠标活动的代码
private void NotifyMouseMove(Point newPoint)
{
if (newPoint.X > _LastPoint.X)
{
lbl1.Text = "Move Left.";
}
else
{
lbl1.Text = "Move Left.";
}

if (newPoint.Y > _LastPoint.Y)
{
lbl1.Text = "Move Down.";
}
else
{
lbl1.Text = "Move Up.";
}
}

在你的弹出窗口的Form_Load事件中写上TextBox1.Focus

记下上一个点的坐标来判断

用鼠标引发的事件 事件都传了2个参数,一个sender