一個WPF控制項 詭異的MouseEvent 。

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   2014   

背景:
 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; }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.