A strange mouseevent of the WPF control.

Source: Internet
Author: User
Background:
 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 );

A WPF border control and registers mouse events.

 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;            }        }
Procedure:

1. Click the left mouse button to trigger touch_mouseleftbuttondown once,

2. Move the mouse to trigger touch_mousemove (Note: if the mouse does not move at a certain point, the same coordinates will only be triggered once, and the event will not be triggered again, if you move the mouse again ),

3. Trigger touch_mouseleave (touch_mouseleftbuttonup) once when the mouse leaves (or the left button is released.

Problem:

1. correspond to the above operations on my computer, including the number of triggering events.

My Computer Configuration:

 

2. But it is different on the second computer,

When the mouse does not move in 2nd processes, it will trigger more than 10 times and then it will not be triggered (that is, the same coordinates will trigger more than 10 touch_mousemove and then no longer trigger)

3rd processes are also triggered more than 10 times, and then the trigger is stopped.

Second Computer Configuration:

 

Solution:

What I want is, of course, the normal operation process on my computer, to synchronize to another computer.

I changed the code, but I don't know why there is such a difference.

1. Add touch_mousemove to determine whether the last coordinate is the same as the current coordinate. If it is the same, return
     if (_currentPoint == _lastPoint) return;     _lastPoint = _currentPoint;

2. touch_mouseleftbuttonup/touch_mouseleave add judgment
 if (this._mouseDown) {    this._mouseDown = false; }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.