加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – WPF MouseButtonEventArgs时间戳值是负数?

发布时间:2020-12-15 08:24:51 所属栏目:百科 来源:网络整理
导读:我有一些 WPF触发器的代码,用于检查双击: private void HandleButtonUp(object sender,MouseButtonEventArgs mouseEventArgs) { if (mouseEventArgs.ChangedButton == MouseButton.Left (mouseEventArgs.Timestamp - _lastClick) SystemInfo.DoubleClickTim
我有一些 WPF触发器的代码,用于检查双击:
private void HandleButtonUp(object sender,MouseButtonEventArgs mouseEventArgs)
    {
        if (mouseEventArgs.ChangedButton == MouseButton.Left &&
            (mouseEventArgs.Timestamp - _lastClick) < SystemInfo.DoubleClickTime)
        {
            this.InvokeActions(mouseEventArgs);
            _lastClick = 0; // Require 2 clicks again
        }
        else 
            _lastClick = mouseEventArgs.Timestamp;
    }

这一直运作良好.但是今天,突然单击即可调用该操作.当我检查代码时,我发现时间戳值为负,这导致它总是小于SystemInfo.DoubleClickTime(500是我的设置).

这是正常的吗?为什么突然改变了?

解决方法

InputEventArgs.Timestamp属性的行为类似于 Environment.TickCount,您可以在其中找到以下备注:

The value of this property is derived from the system timer and is
stored as a 32-bit signed integer. Consequently,if the system runs
continuously,TickCount will increment from zero to Int32.MaxValue for
approximately 24.9 days,then jump to Int32.MinValue,which is a
negative number,then increment back to zero during the next 24.9
days.

TickCount is different from the Ticks property,which is the number of
100-nanosecond intervals that have elapsed since 1/1/0001,12:00am.

Use the DateTime.Now property to obtain the current local date and
time on this computer.

忽略跳转发生时的罕见情况(24.9天后,然后每49.7天),您可以这样检查:

Math.Abs(mouseEventArgs.Timestamp - _lastClick) < SystemInfo.DoubleClickTime

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读