Windows 8 utility tip series: 4. Common mouse events for Windows 8

Source: Internet
Author: User

In Windows 8, some new mouse events are used to replace the previous Silverlight mouse events. The common events are as follows:

Pointerwheelchanged: Specifies a sliding event in the middle mouse.

Pointerpressed: the event is triggered when the mouse clicks down.

Pointerreleased: this event is triggered when you release the mouse when you click it.

Pointerentered: triggered once when the mouse enters the valid range.

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

Pointerexited: triggered when the mouse exits the valid range.

In this article, we will use examples to demonstrate the response of various mouse events. The instance source code is as follows:

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">        <Canvas Name="MainCanvas" Width="600" Height="300" Background="Cornsilk"                PointerWheelChanged="MainCanvas_PointerWheelChanged"                 PointerReleased="MainCanvas_PointerReleased"                PointerPressed="MainCanvas_PointerPressed"                PointerMoved="MainCanvas_PointerMoved"                PointerExited="MainCanvas_PointerExited"                PointerEntered="MainCanvas_PointerEntered"                ></Canvas>        <TextBlock HorizontalAlignment="Left" Foreground="Gold" Margin="383,99,0,0" TextWrapping="Wrap"                    Name="tbLabel" Text="" VerticalAlignment="Top" Height="40" Width="418"/>        <TextBlock HorizontalAlignment="Left" Foreground="Gold" Margin="774,99,0,0" TextWrapping="Wrap"                    Name="tbLabelNext" Text="" VerticalAlignment="Top" Height="40" Width="209"/>        <TextBlock HorizontalAlignment="Left" Foreground="Gold" Margin="564,171,0,0" TextWrapping="Wrap"                    Name="tbLabelFore" Text="" VerticalAlignment="Top" Height="40" Width="209"/>    </Grid>

The following is the background code of XAML. CS,

/// <Summary> /// it can be used to itself or navigate to a blank page inside the frame. /// </Summary> Public sealed partial class mainpage: Page {public mainpage () {This. initializecomponent ();} Point start = new point (); // <summary> // This page will be called when it is displayed in the frame. /// </Summary> /// <Param name = "E"> describes how to access event data on this page. Parameter // properties are usually used on the configuration page. </Param> protected override void onnavigatedto (navigationeventargs e) {}// specify the private void maincanvas_pointerwheelchanged (Object sender, pointerroutedeventargs e) {This. tblabel. TEXT = "slide one mouse arrow";} // Private void maincanvas_pointerpressed (Object sender, pointerroutedeventargs e) {start = E. getcurrentpoint (maincanvas ). position; this. tblabel. TEXT = "one mouse or screen clicked";} // The Private void maincanvas_pointerreleased (Object sender, pointerroutedeventargs e) {Point End = E. getcurrentpoint (maincanvas ). position; double angle = 0; // determines the drag angle if (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 = "one mouse or screen clicked";} else if (angle >=45 & angle <135) {This. tblabelfore. TEXT = "from bottom up";} else if (angle <=45 | angle> 315) {This. tblabelfore. TEXT = "sliding from left to right";} else if (angle >=135 & angle <225) {This. tblabelfore. TEXT = "sliding from right to left";} else if (angle >=225 & angle <315) {This. tblabelfore. TEXT = "Top Down" ;}}// move the cursor over the private void maincanvas_pointermoved (Object sender, pointerroutedeventargs e) {point = E. getcurrentpoint (maincanvas ). position; this. tblabel. TEXT = "The mouse is moving X:" + point. X + ", Y:" + point. y;} // Private void maincanvas_pointerexited (Object sender, pointerroutedeventargs e) {This. tblabelnext. TEXT = "move the mouse out of the range";} // enter the range event private void maincanvas_pointerentered (Object sender, pointerroutedeventargs e) {This. tblabelnext. TEXT = "move the mouse into the range ";}}

Is the effect demonstration. If you need the source code, click win8event.zip to download it.

Related Article

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.