一个WPF控件 诡异的MouseEvent 。

背景:

 private System.Windows.Controls.Border _borderTouch;
private bool _mouseDown = false;

   private System.Windows.Point _currentPoint = new System.Windows.Point(0, 0);
    private System.Windows.Point _lastPoint = new System.Windows.Point(0, 0);

一个wpf Border控件,然后注册鼠标事件

 touch.MouseLeftButtonDown += new MouseButtonEventHandler(touch_MouseLeftButtonDown);
 touch.MouseLeftButtonUp += new MouseButtonEventHandler(touch_MouseLeftButtonUp);
 touch.MouseLeave += new MouseEventHandler(touch_MouseLeave);
 touch.MouseMove += new MouseEventHandler(touch_MouseMove);
    private void touch_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            //if (this._mouseDown)
            //{
                this._mouseDown = false;
            //}
        }
        private void touch_MouseLeave(object sender, MouseEventArgs e)
        {
            //if (this._mouseDown)
            //{
                this._mouseDown = false;
            //}
        }
        private void touch_MouseMove(object sender, MouseEventArgs e)
        {
            if (this._mouseDown)
            {
                _currentPoint = e.GetPosition(this._borderTouch);
                //if (_currentPoint == _lastPoint) return;
                //_lastPoint = _currentPoint;
            }
        }
        private void touch_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!this._mouseDown)
            {
                this._mouseDown = true;
                _currentPoint = e.GetPosition(this._borderTouch);
                //_lastPoint = _currentPoint;
            }
        }

操作过程:

1. 点鼠标左键触发touch_MouseLeftButtonDown一次,

2. 然后移动鼠标触发touch_MouseMove(注明:如果鼠标在某点不动,相同坐标只触发一次,然后事件不再触发,如果再移动接触发),

3. 鼠标离开(或者左键松开)触发touch_MouseLeave(touch_MouseLeftButtonUp)一次

问题:

1. 在我的电脑上对应以上操作过程包括触发事件的次数。

我的电脑配置:

2. 但是在第二个电脑上就不一样,

第2个过程鼠标不动的时候会触发10多次然后就不触发啦(也就是说相同的坐标会触发10多次touch_MouseMove然后不再触发

第3个过程也是触发10多次,然后停止触发。

第二个电脑配置:

解决:

我想要的当然是我电脑上的正常操作过程,为同步另一台电脑。

我改啦下代码,但是我不知道为什么会有这样的差异。

1. touch_MouseMove   添加判断上一次的坐标和现在的坐标是否相同,如果相同就return
     if (_currentPoint == _lastPoint) return;
     _lastPoint = _currentPoint;

2. touch_MouseLeftButtonUp/touch_MouseLeave 添加判断
 if (this._mouseDown)
 {
    this._mouseDown = false;
 }
原文地址:https://www.cnblogs.com/kissfu/p/3812390.html