区分 Click 和 DoubleClick 的方法
我在面板中有一个包含一些对象的 GDI 绘图。
当用户单击一个对象时,应选择该对象,如果双击它,应打开一个新的弹出(属性)窗口。
现在,我覆盖了OnMouseClick
=> obj.Selected = 不是 obj.Selected
OnMouseDoubleClick
=> (New Properties(obj)).ShowDialog()
问题是,当弹出窗口打开时(由于 DoubleClick),对象被选中(由于 Click)。有没有办法避免(忽略)这个中间的点击?
(比如说,在实际项目中我不使用点击,甚至不使用 MouseDown
,但是问题保持不变)
I have in a panel a GDI drawing with some objects.
When the user clicks on one object, this object should be selected, if doubleClicks on it, a new pop-up (properties) window should open.
Now, I overridedOnMouseClick
=> obj.Selected = Not obj.Selected
OnMouseDoubleClick
=> (New Properties(obj)).ShowDialog()
The problem is that when the pop-up opens (because of DoubleClick), the object became selected (because of the Click). Is there away to avoid (ignore) this intermediate Click?
(Say, in the real project I don't use click but even MouseDown
, however, the question remain the same)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如何使用 MouseEventArgs 的 Clicks 属性?
How about using the Clicks property of MouseEventArgs?
当您收到单击事件时,您可以(使用计时器或任何其他延迟机制)将选择操作延迟稍长于
SystemInformation.DoubleClickTime
。如果在该时间段内发生另一个MouseDown
事件,则该事件是双击,因此您应该取消排队的选择操作。When you get the click event, you can (using a timer or any other delay mechanism) delay the select action by slightly longer than specified by
SystemInformation.DoubleClickTime
. If anotherMouseDown
event happens within that time period it is a double-click, so then you should cancel the queued select action.保留 MouseClick 事件处理程序不变,仅将另一个
obj.Selected = Not obj.Selected
添加到 DoubleClick 事件处理程序怎么样?这当然会导致双击选择取消选择序列(或其他方式),我不知道用户是否会识别闪烁,但我想值得一试,而且没有计时器会更容易。
编辑:
如果有任何事件处理程序附加到目标对象的 SelectionChanged 事件,则这种相当实用的解决方案不起作用,因为它会在根本不应该触发的地方触发两次。
What about leaving the MouseClick event handler as it is and just add another
obj.Selected = Not obj.Selected
to the DoubleClick event handler?That of course results in a select unselect sequence (or other way around) for the double click and I don't know if the blinking will be recognized by the user but I guess it's worth a try and it's much easier without the timer.
edit:
This rather pragmatic solution doesn't work if there is any event handler attached to the SelectionChanged event of the target object because it would trigger twice where it shouldn't trigger at all.