在WPF中获取系统的双击计时器间隔(来自控制面板的值)
我有一个 FrameworkElement,我想在用户单击时执行操作 A,在用户双击时执行操作 B。
由于事件的传递方式,我总是收到一个开始操作 A 的单击事件。环顾四周后,我发现 这里有一个有趣的技术,使用计时器来延迟处理点击次数。然而,本示例将计时器硬编码为 300 毫秒,但我更愿意使用用户的“双击速度”设置控制面板的鼠标属性对话框。
用于从系统获取该值的 wpf/C# API 是什么?
I have a FrameworkElement and I want to perform action A when the user single clicks, and action B when the user double clicks.
Due to the way events are delivered, I always get a single click event which begins action A. After looking around, I found an interesting technique here using a timer to delay the handling of the clicks. However, this example hardcodes the timer to 300 milliseconds, but I would prefer to use the user's "Double-click speed" setting Control Panel's Mouse Properties dialog.
What's the wpf/C# API for getting that value from the system?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在此处找到时间:System.Windows .Forms.SystemInformation.DoubleClickTime
您实际上可以在这里看到您想要实现的目标的完整实现:
WPF:按钮单击+双击问题
You can find the time here: System.Windows.Forms.SystemInformation.DoubleClickTime
You can actually see a full implementation of what you are trying to achieve here:
WPF: Button single click + double click issue
如果您不想引用 System.Windows.Forms 程序集,您可以尝试以下操作:
If you don't want reference System.Windows.Forms assembly, you can try this:
这应该有效 SystemInformation.DoubleClickTime
This should work SystemInformation.DoubleClickTime
如果您正在处理提供
MouseButtonEventArgs
的事件(例如UIElement.MouseLeftButtonDown
),则可以访问MouseButtonEventArgs.ClickCount
来确定是否多次点击都发生在彼此的双击时间内。由于FrameworkElement
派生自UIElement
这在您的情况下应该是可能的。无需使用 DllImport 或 WinForms,因为您实际上不需要知道双击时间来完成您的主要目标。
编辑添加:我发现这仅适用于 ButtonDown 事件(左或右)。我不确定为什么他们没有为 ButtonUp 事件正确实现这一点,但它应该足以捕获这两个事件,并保留 ButtonDown 中的 ClickCount 的成员变量,您可以在接收 ButtonUp 时检查该变量。
If you're handling an event that provides a
MouseButtonEventArgs
, such asUIElement.MouseLeftButtonDown
, you can accessMouseButtonEventArgs.ClickCount
to determine if multiple clicks have happened within the double-click time of each other. SinceFrameworkElement
derives fromUIElement
this should be possible in your case.No need to use DllImport or WinForms, as you don't really need to know the double-click time to accomplish your main goal.
Edit add: I discovered that this only really works for the ButtonDown events (left or right). I'm not sure why they didn't implement this properly for the ButtonUp events, but it should suffice to catch both events, and keep a member variable of the ClickCount from the ButtonDown that you can check when receiving ButtonUp.