Windows Store Apps note003 about cursor(pointer)
来源:互联网 发布:js获取audio时长 编辑:程序博客网 时间:2024/06/06 11:01
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;
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.
- Windows Store Apps note003 about cursor(pointer)
- Windows Store Apps note001 about image basic operation
- Windows Store Apps note002 about TextBlock TextBox PasswordBox
- Windows Store apps开发[25]Metro style apps改名为Windows Store apps
- Windows Store apps开发[23]创建Windows Store应用程序包
- cursor:pointer
- cursor:pointer
- Windows Store apps开发[1]平台简介
- Windows Store apps开发[13]应用程序生命周期
- Windows Store apps开发[44]AppBar总结
- Windows Store apps开发[49]自定义MessageDialog
- Windows Store apps开发[50]自定义Popup
- 重新想象 Windows 8 Store Apps (8)
- 重新想象 Windows 8 Store Apps (9)
- 重新想象 Windows 8 Store Apps (15)
- 重新想象 Windows 8 Store Apps (16)
- Css Bug In Windows Store apps
- 重新想象 Windows 8 Store Apps (32)
- ORACLE的sign函数和DECODE函数
- online_judge_1061
- 安卓 Bitmap基本使用
- DB9串及交叉与直通线
- MATLAB神经网络编程(一)——感知器
- Windows Store Apps note003 about cursor(pointer)
- “error LNK1169: 找到一个或多个多重定义的符号”的解决方法
- 三、RFID系统组成及其功能(第一次作业)
- static变量利用常量和变量初始化的不同
- ACM--steps--dyx--1.3.8--Fighting for HDU
- Android Metro风格的Launcher开发系列第一篇
- CSS中的position
- 2. 程序员生存定律--程序人生的出口
- android中单选列表对话框-选择个人特长