Windows Store Apps note003 about cursor(pointer)

There are a lot functions for cursor in win8.1 store apps:


1. PointerEntered: once the cursor is in the element's area;

2. PointerExited: once the cursor is out of the element's area;

3.PointerMoved: once the cursor move in the element's area;

4.PointerPressed: once the cursor's keys(any kind of key) are pressed in the element's area, but notice that if the element is button(or something of this kind) the effect will be different;

5.PointerReleased: once the cursor's keys(any kind of key) are released from being pressed in the element's area, but notice that the same problem as PointerPressed;

6.PointerWheelChanged: once the cursor's wheel is changed in the element's area.


So what kind of forms of cursor can be showed?

https://msdn.microsoft.com/zh-cn/library/windows/apps/windows.ui.core.corecursortype.aspx?f=255&MSPPError=-2147217396


The code below shows:

1.The usage of the functions above;

2.The difference between button and textblock when the cursor's keys are pressed or released;

3.How to specify a key(left, mid, right keys) to be pressed or released.

    <Grid Background="Navy">

        <Button x:Name="Button1" Content="Move The Pointer On Me 4 help" HorizontalAlignment="Left" Margin="49,46,0,0" VerticalAlignment="Top" Height="50" Width="248"/>
        <Button x:Name="Button2" Content="Move out to reset" HorizontalAlignment="Left" Margin="49,110,0,0" VerticalAlignment="Top" Height="50" Width="248"/>
        <TextBlock x:Name="TextBlock" Text="Press me to be different" HorizontalAlignment="Left" Margin="46,169,0,0" VerticalAlignment="Top" Height="29" Width="248" FontSize="23"/>
        <Button x:Name="Button3" Content="Press me to be different" HorizontalAlignment="Left" Margin="49,200,0,0" VerticalAlignment="Top" Height="45" Width="248"/>
        <Button x:Name="Button4" Content="Move for wait and wheel 4 NS" HorizontalAlignment="Left" Margin="49,256,0,0" VerticalAlignment="Top" Height="45" Width="248"/>
        <Button x:Name="ArrowButton" Content="Arrow" HorizontalAlignment="Left" Height="42" Margin="49,310,0,0" VerticalAlignment="Top" Width="245"/>
        <Button x:Name="CrossButton" Content="Cross" HorizontalAlignment="Left" Height="42" Margin="49,350,0,0" VerticalAlignment="Top" Width="245"/>
        <Button x:Name="HandButton" Content="Hand" HorizontalAlignment="Left" Height="42" Margin="49,390,0,0" VerticalAlignment="Top" Width="245"/>
        <Button x:Name="HelpButton" Content="Help" HorizontalAlignment="Left" Height="42" Margin="49,430,0,0" VerticalAlignment="Top" Width="245"/>
        <Button x:Name="IBeamButton" Content="IBeam" HorizontalAlignment="Left" Height="42" Margin="321,46,0,0" VerticalAlignment="Top" Width="245"/>
        <Button x:Name="SizeAllButton" Content="SizeAll" HorizontalAlignment="Left" Height="42" Margin="321,86,0,0" VerticalAlignment="Top" Width="245"/>
        <Button x:Name="SizeNortheastSouthwestButton" Content="SizeNortheastSouthwest" HorizontalAlignment="Left" Height="42" Margin="321,126,0,0" VerticalAlignment="Top" Width="245"/>
        <Button x:Name="SizeNorthSouthButton" Content="SizeNorthSouth" HorizontalAlignment="Left" Height="42" Margin="321,166,0,0" VerticalAlignment="Top" Width="245"/>
        <Button x:Name="SizeNorthwestSoutheastButton" Content="SizeNorthwestSoutheast" HorizontalAlignment="Left" Height="42" Margin="321,206,0,0" VerticalAlignment="Top" Width="245"/>
        <Button x:Name="SizeWestEastButton" Content="SizeWestEast" HorizontalAlignment="Left" Height="42" Margin="321,246,0,0" VerticalAlignment="Top" Width="245"/>
        <Button x:Name="UniversalNoButton" Content="UniversalNo" HorizontalAlignment="Left" Height="42" Margin="321,286,0,0" VerticalAlignment="Top" Width="245"/>
        <Button x:Name="UpArrowButton" Content="UpArrow" HorizontalAlignment="Left" Height="42" Margin="321,326,0,0" VerticalAlignment="Top" Width="245"/>
        <Button x:Name="WaitButton" Content="Wait" HorizontalAlignment="Left" Height="42" Margin="321,366,0,0" VerticalAlignment="Top" Width="245"/>
        <TextBlock x:Name="SelfDefinitionButton" Text="   L Cross/R Hand/M Wait" HorizontalAlignment="Left" Height="23" Margin="321,415,0,0" VerticalAlignment="Top" FontSize="20" Width="242" PointerPressed="SelfDefinitionButton_PointerPressed"/>

    </Grid>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace test013
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();

            Button1.PointerEntered += buttonPointerEnteredHelp;

            Button2.PointerExited += buttonPointerEnteredArrow;

            TextBlock.PointerPressed += buttonPointerEnteredSizeAll;
            TextBlock.PointerReleased += buttonPointerEnteredWait;

            Button3.PointerPressed += buttonPointerEnteredSizeAll;
            Button3.PointerReleased += buttonPointerEnteredWait;

            Button4.PointerMoved += buttonPointerEnteredWait;
            Button4.PointerWheelChanged += buttonPointerEnteredSizeNorthSouth;

            ArrowButton.PointerEntered += buttonPointerEnteredArrow;
            CrossButton.PointerEntered += buttonPointerEnteredCross;
            HandButton.PointerEntered += buttonPointerEnteredHand;
            HelpButton.PointerEntered += buttonPointerEnteredHelp;
            IBeamButton.PointerEntered += buttonPointerEnteredIBeam;
            SizeAllButton.PointerEntered += buttonPointerEnteredSizeAll;
            SizeNortheastSouthwestButton.PointerEntered += buttonPointerEnteredSizeNortheastSouthwest;
            SizeNorthSouthButton.PointerEntered += buttonPointerEnteredSizeNorthSouth;
            SizeNorthwestSoutheastButton.PointerEntered += buttonPointerEnteredSizeNorthwestSoutheast;
            SizeWestEastButton.PointerEntered += buttonPointerEnteredSizeWestEast;
            UniversalNoButton.PointerEntered += buttonPointerEnteredUniversalNo;
            UpArrowButton.PointerEntered += buttonPointerEnteredUpArrow;
            WaitButton.PointerEntered += buttonPointerEnteredWait;
        }
        private void SelfDefinitionButton_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
            {
                var properties = e.GetCurrentPoint(this).Properties;
                if (properties.IsLeftButtonPressed)
                {
                    Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Cross, 1);
                }
                else if (properties.IsRightButtonPressed)
                {
                    Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand, 1);
                }
                else if (properties.IsMiddleButtonPressed)
                {
                    Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 1);
                }
            }
        }
        void buttonPointerEnteredArrow(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 1);
        }
        void buttonPointerEnteredCross(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Cross, 1);
        }
        void buttonPointerEnteredCustom(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Custom, 101);
        }
        void buttonPointerEnteredHand(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand, 1);
        }
        void buttonPointerEnteredHelp(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Help, 1);
        }
        void buttonPointerEnteredIBeam(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.IBeam, 1);
        }
        void buttonPointerEnteredSizeAll(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeAll, 1);
        }
        void buttonPointerEnteredSizeNortheastSouthwest(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeNortheastSouthwest, 1);
        }
        void buttonPointerEnteredSizeNorthSouth(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeNorthSouth, 1);
        }
        void buttonPointerEnteredSizeNorthwestSoutheast(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeNorthwestSoutheast, 1);
        }
        void buttonPointerEnteredSizeWestEast(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeWestEast, 1);
        }
        void buttonPointerEnteredUniversalNo(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.UniversalNo, 1);
        }
        void buttonPointerEnteredUpArrow(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.UpArrow, 1);
        }
        void buttonPointerEnteredWait(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 1);
        }
        void buttonPointerExited(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 1);
        }
    }
}
1. PointerEntered:
Button1.PointerEntered += buttonPointerEnteredHelp;



2.PointerExited:
Button2.PointerExited += buttonPointerEnteredArrow;


3.PointerPressed and PointerReleased in TextBlock and Button:

TextBlock.PointerPressed += buttonPointerEnteredSizeAll;
TextBlock.PointerReleased += buttonPointerEnteredWait;

Button3.PointerPressed += buttonPointerEnteredSizeAll;
Button3.PointerReleased += buttonPointerEnteredWait;
Any kind of key of cursor is pressed on TextBlock(Including left, mid, right, function key except DPI):


Any kind of key of cursor is released from being pressed on TextBlock(Including left, mid, right, function key except DPI):

So what's the differences between TextBlock and Button?

For left key, PointerPressed and PointerReleased don't work:


For right key, PointerPressed and PointerReleased work as in TextBlock;

For other keys except DPI, being clicked is being pressed. It means that PointerPressed still work but "press" doesn't cause it while "click" can do that, and PointerReleased doesn't work:


4. PointerMoved and PointerWheelChanged

Button4.PointerMoved += buttonPointerEnteredWait;
Button4.PointerWheelChanged += buttonPointerEnteredSizeNorthSouth;


5.CoreCursorType members:

ArrowButton.PointerEntered += buttonPointerEnteredArrow;
CrossButton.PointerEntered += buttonPointerEnteredCross;
HandButton.PointerEntered += buttonPointerEnteredHand;
HelpButton.PointerEntered += buttonPointerEnteredHelp;
IBeamButton.PointerEntered += buttonPointerEnteredIBeam;
SizeAllButton.PointerEntered += buttonPointerEnteredSizeAll;
SizeNortheastSouthwestButton.PointerEntered += buttonPointerEnteredSizeNortheastSouthwest;
SizeNorthSouthButton.PointerEntered += buttonPointerEnteredSizeNorthSouth;
SizeNorthwestSoutheastButton.PointerEntered += buttonPointerEnteredSizeNorthwestSoutheast;
SizeWestEastButton.PointerEntered += buttonPointerEnteredSizeWestEast;
UniversalNoButton.PointerEntered += buttonPointerEnteredUniversalNo;
UpArrowButton.PointerEntered += buttonPointerEnteredUpArrow;
WaitButton.PointerEntered += buttonPointerEnteredWait;



6.Specify a key(left, mid, right keys) to be pressed or released:

<TextBlock x:Name="SelfDefinitionButton" Text="   L Cross/R Hand/M Wait" HorizontalAlignment="Left" Height="23" Margin="321,415,0,0" VerticalAlignment="Top" FontSize="20" Width="242" PointerPressed="SelfDefinitionButton_PointerPressed"/>
private void SelfDefinitionButton_PointerPressed(object sender, PointerRoutedEventArgs e)
{
    if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
    {
        var properties = e.GetCurrentPoint(this).Properties;
        if (properties.IsLeftButtonPressed)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Cross, 1);
        }
        else if (properties.IsRightButtonPressed)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand, 1);
        }
        else if (properties.IsMiddleButtonPressed)
        {
            Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Wait, 1);
        }
    }
}






7.Custom cursor is still unknown for me, i will update this article as soon as possible.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值