Getting Started with Windows 8 Development (iv) Common mouse events for Windows 8

Source: Internet
Author: User
Tags abs range valid blank page

A number of new mouse events are used in Windows 8 to replace previously Silverlight mouse events with the following common events:

Pointerwheelchanged: The middle mouse button sliding event.

Pointerpressed: When the mouse clicks down, the event is triggered.

Pointerreleased: When the mouse clicks down when releasing the mouse triggers the event.

Pointerentered: Triggers once when the mouse enters a valid range.

Pointermoved: Triggers an event when the mouse moves within a valid range.

Pointerexited: Triggers an event when the mouse exits a valid range.

The responses to various mouse events are demonstrated in this article through an instance. Below we look at the example source code as follows:

<grid background= "{StaticResource Applicationpagebackgroundthemebrush}" > <canvas Name= "MainCanvas"
                Width= "height=" background= "Cornsilk" pointerwheelchanged= "maincanvas_pointerwheelchanged"
                Pointerreleased= "maincanvas_pointerreleased" pointerpressed= "maincanvas_pointerpressed" Pointermoved= "maincanvas_pointermoved" pointerexited= "maincanvas_pointerexited" Po Interentered= "maincanvas_pointerentered" ></Canvas> <textblock horizontalalignment= "Left" foreground= "Gold" margin= "383,99,0,0" textwrapping= "Wrap" name= "Tblabel" text= "VERTICALALIGNM" " Ent= "Top" height= "width=" 418 "/> <textblock horizontalalignment=" left "foreground=" Gold "margin=" 774 , 99,0,0 "textwrapping=" Wrap "name=" Tblabelnext "text=" "verticalalignment=" Top "height=" "width=" 209 "/> <teXtblock horizontalalignment= "left" foreground= "Gold" margin= "564,171,0,0" textwrapping= "Wrap" name= "TB" Labelfore "text=" "verticalalignment=" Top "height=" width= "209"/> </Grid>

Where the Xaml.cs background code is as follows,

<summary>///can be used for itself or to navigate to a blank page inside the Frame.    
            </summary> public sealed partial class Mainpage:page {public MainPage () { This.   
        InitializeComponent ();   
       
        Point start = new Point ();   
        <summary>///is called when this page is to be displayed in the Frame. </summary>///<param name= "E" > Describes how to access event data for this page. The Parameter///property is typically used to configure the page.   
       
        </param> protected override void Onnavigatedto (NavigationEventArgs e) {} middle mouse button sliding event private void maincanvas_pointerwheelchanged (object sender, Pointerroutedeventargs   
        E) {this.tbLabel.Text = "sliding a mouse in arrow"; //mouse click event private void Maincanvas_pointerpressed (object sender, Pointerroutedeventargs E ) {start = E.getcurrentpoint (Maincanvas).   
   Position;         This.tbLabel.Text = "clicked a mouse or screen";   
        }//mouse button event private void Maincanvas_pointerreleased (object sender, Pointerroutedeventargs e) {Point end = E.getcurrentpoint (Maincanvas).   
            Position;   
            Double angle = 0; Determine if the drag mouse angle is math.abs (end. X-start. X) < 1 && math.abs (end. Y-start.   
            Y) < 1) {angle = 0; else if (end. X > Start. X) {if (end. Y > Start. Y) {angle = 360-math.atan (end. Y-start. Y) * 1.0/(end. X-start.   
                X)) * 180/MATH.PI; else {angle = Math.atan (start. Y-end. Y) * 1.0/(end. X-start.   
                X)) * 180/MATH.PI; } else if (end. X < start.  X) { 
                if (end. Y > Start. Y) {angle = Math.atan (end. Y-start. Y) * 1.0/(start. X-end.   
                X)) * 180/math.pi + 180; else {angle = 180-math.atan (start. Y-end. Y) * 1.0/(start. X-end.   
                X)) * 180/MATH.PI;   
            } if (angle = 0) {This.tbLabel.Text = "clicked a mouse or screen"; else if (angle >= && Angle < 135) {This   
            . Tblabelfore.text = "From the bottom up"; else if (angle <= | | angle > 315) {this.tbLabelFore.Text = "from   
            Slide left to right "; else if (angle >= 135 && Angle <) {This.tblabelfore.   
            Text = "Slide from right to left"; else if (angle >=;& Angle < 315) {This.tbLabelFore.Text = "from top down"; }//mouse move event private void Maincanvas_pointermoved (object sender, Pointerroutedeventargs e) {Point point = E.getcurrentpoint (Maincanvas).   
            Position; This.tbLabel.Text = "The mouse is moving x:" +point. X+ ", Y:" +point.   
        Y   
        }//Mouse out range event private void maincanvas_pointerexited (object sender, Pointerroutedeventargs e)   
        {This.tbLabelNext.Text = "mouse move out of scope";    
        }//mouse into range event private void maincanvas_pointerentered (object sender, Pointerroutedeventargs e)   
        {This.tbLabelNext.Text = "mouse into the range"; }   
    }

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.