区分 Click 和 DoubleClick 的方法

发布于 2024-09-13 20:07:52 字数 415 浏览 5 评论 0原文

我在面板中有一个包含一些对象的 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 overrided
OnMouseClick => 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

水中月 2024-09-20 20:07:52

当您收到单击事件时,您可以(使用计时器或任何其他延迟机制)将选择操作延迟稍长于 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 another MouseDown event happens within that time period it is a double-click, so then you should cancel the queued select action.

墨洒年华 2024-09-20 20:07:52

保留 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文