Win10 UWP Get button left mouse click

Source: Internet
Author: User

We can use pointerpressed to get the right mouse button down, but how do we get left button.

In fact, UWP has no mouseleftbuttondown, so we can use a simple way to get the left mouse button press.

We write a Button in XAML, give him the name MyButton

So we write a pointerpressed function in Xaml.cs and add it to our Button pointerpressedevent

        Public MainPage ()
        {this
            . InitializeComponent ();
            Mybutton.addhandler (pointerpressedevent,
                new Pointereventhandler (button_onpointerpressed), true);

        private void Button_onpointerpressed (object sender, Pointerroutedeventargs e)
        {

        }

If this is a breakpoint in the function, you can see that our left and right button press will trigger.

But how do we know if we pressed the left or right button.

We can use E. Handle, if it is true, then the left button, if it is false, then the right key.

This method is simple.

But this is not a good way, we can use Getcurrentpoint isleftbuttonpressed to know that we are left click

            var temp = e.getcurrentpoint (sender as Button);

            if (temp. properties.isleftbuttonpressed)
            {
                _leftmouse = true;
            }

If we just left the button, then we can use the tapped

Tap can get a mouse, pressed point, which is useful when popping up.

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.