鼠标光标位置的变化 [英] Mouse Cursor position changes

查看:271
本文介绍了鼠标光标位置的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有我想要移动我的鼠标,然后会的DragDrop功能Windows窗体应用程序,但我一直在使用鼠标移动的鼠标事件做尝试,但似乎像的DragDrop非常sensitive.So什么我问的是是否有可能检测当将鼠标光标移动的至少一个一定距离从当前光标然后它执行的DragDrop代码。

Hi I have a windows form application which i want to move my mouse then dragdrop will function but i have tried using mousemove mouse event to do it , but seems like dragdrop is very sensitive.So what i'm asking is whether is it possible to detect if the mouse cursor moves at least a certain distance away from the current cursor then it does the dragdrop code.

推荐答案

我知道你有一个拖放放大器;落码只希望如果鼠标移动一定的距离来执行。如果是这样的:

I understand you have a drag & drop code you want to execute only if the mouse has moved a certain distance. If so:

您可以勾鼠标移动事件一旦用户进行了初次动作(上拖动鼠标项下?)。然后比较鼠标移动事件的鼠标坐标,并引发了的DragDrop码一旦坐标的区别是高于你设置的任意值。

You can hook to the mouse move event once the user has performed the initial action (mouse down on the item to drag ?). Then compare the mouse coordinates on the mouse move event and trigger the "dragdrop code" once the coordinates difference is higher then the arbitrary value you set.

private int difference = 10;
private int xPosition;
private int yPosition;

private void item_MouseDown(object sender, MouseEventArgs e) 
{
    this.MouseMove += new MouseEventHandler(Form_MouseMove);
    xPosition = e.X;
    yPosition = e.Y;
}

private void Form_MouseMove(object sender, MouseEventArgs e) 
{
    if (e.X < xPosition - difference
        || e.X > xPosition + difference
        || e.Y < yPosition - difference
        || e.Y > yPosition + difference) 
    {
        //Execute "dragdrop" code
        this.MouseMove -= Form_MouseMove;
    }
}



当光标移出的这将执行的DragDrop虚拟10×10平方。

This would execute dragdrop when the cursor moves out of a virtual 10x10 square.

这篇关于鼠标光标位置的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆