鼠标按下和点击冲突 [英] MouseDown and Click conflict

查看:298
本文介绍了鼠标按下和点击冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有form_MouseDown事件拖动()方法。我也有在窗体上的单击事件。问题是,如果我点击的形式,MouseDown事件被触发,它永远不会触发click事件的机会。



什么是解决这一问题的最佳方式是什么?我在想计数的像素,如果形式实际上是拖,但必须有一个更好的办法。有什么建议么?


解决方案

我想计数的像素,如果形式实际上是拖,但必须有一个更好的办法。




不,这正是你怎么也得做。



这不只是一个软件的限制;这是非常实用的一个作为好。如果你想通过从用户的角度看问题,你会立即看到的问题以及解决方案。问问自己,什么是点击和拖动的区别?



他们两个鼠标按钮下降了对象开始,但其中一人在结束鼠标按钮回去了超过在相同的位置上的对象,而另一个用鼠标按钮,在一个完全不同的位置要备份结束



由于时间机器避难所'。 ŧ日臻完善呢,你不知道这提前的方式。



所以,是的,你需要保持某种距离阈值,而如果外指针移动这距离阈值,而这是下跌超过对象,那么你认为这是一个拖累。否则,你认为这是一个点击。



这距离阈值不应该是0,用户不应该要求按住鼠标的完全静止的为了启动一个拖累。很多用户都是低于标准杆捕鼠。试图点击时,它们很可能略微抽搐。如果阈值为0,他们最终会做很多意外拖着,当他们尝试点击。



当然,你实际上并不担心任何这还是你自己计算的拖动阈值。相反,通过调用 GetSystemMetrics的功能并指定为 SM_CXDRAG SM_CYDRAG 。 (这可能是由的WinForms框架的地方暴露出来,但我不这么认为,这只是因为容易P /自己调用它们。)

  const int的SM_CXDRAG = 68; 
const int的SM_CYDRAG = 69;
函数[DllImport(user32.dll中)]
静态外部INT GetSystemMetrics的(INT指数);

点GetDragThreshold()
{
返回新点(GetSystemMetrics的(SM_CXDRAG),GetSystemMetrics的(SM_CYDRAG));
}


I have a Drag() method on form_MouseDown event. I also have a click event on the form. The problem is that if I click on the form, MouseDown event gets triggered and it never gets the chance to trigger click event.

What is the best way to solve this issue? I was thinking counting pixels if the form is actually dragged, but there has to be a better way. Any suggestions?

解决方案

I was thinking counting pixels if the form is actually dragged, but there has to be a better way.

Nope, that's exactly how you have to do it.

This isn't just a software limitation; it's very much a practical one as well. If you think through the problem from a user's perspective, you'll immediately see the problem as well as the solution. Ask yourself, what is the difference between a click and a drag?

Both of them start with the mouse button going down over the object, but one of them ends with the mouse button going back up over the object in the same position and the other one ends with the mouse button going back up in a completely different position.

Since time machines haven't been perfected yet, you have no way of knowing this in advance.

So yes, you need to maintain some kind of a distance threshold, and if the pointer moves outside of that distance threshold while it is down over the object, then you consider it a drag. Otherwise, you consider it a click.

That distance threshold should not be 0. The user should not be required to hold the mouse completely still in order to initiate a drag. A lot of users are sub-par mousers. They are very likely to twitch slightly when trying to click. If the threshold is 0, they'll end up doing a lot of inadvertent dragging when they try to click.

Of course, you don't actually have to worry about any of this or compute the drag threshold yourself. Instead, use the Windows default values, obtainable by calling the GetSystemMetrics function and specifying either SM_CXDRAG or SM_CYDRAG. (These might be exposed somewhere by the WinForms framework, but I don't think so. It's just as easy to P/Invoke them yourself.)

const int SM_CXDRAG = 68;
const int SM_CYDRAG = 69;
[DllImport("user32.dll")]
static extern int GetSystemMetrics(int index);

Point GetDragThreshold()
{
    return new Point(GetSystemMetrics(SM_CXDRAG), GetSystemMetrics(SM_CYDRAG));
}

这篇关于鼠标按下和点击冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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