当前位置:网站首页>win10 uwp 改变鼠标
win10 uwp 改变鼠标
2022-08-09 16:53:00 【林德熙】
经常在应用需要修改光标,显示点击、显示输入,但是有些元素不是系统的,那么如何设置鼠标? 本文主要:UWP 设置光标,UWP 移动鼠标
设置光标
需要写一点代码来让程序比较容易看到,什么光标对于什么。
UWP 设置的光标有些看不懂,直接看不知道他是干什么
在xaml写代码:
<StackPanel>
<TextBlock Margin="10,10,10,10" Text="Hand" PointerEntered="button_OnPointerEntered"></TextBlock>
<TextBlock Margin="10,10,10,10" Text="Arrow" PointerEntered="button_OnPointerEntered"></TextBlock>
<TextBlock Margin="10,10,10,10" Text="Cross" PointerEntered="button_OnPointerEntered"></TextBlock>
<TextBlock Margin="10,10,10,10" Text="Help" PointerEntered="button_OnPointerEntered"></TextBlock>
<TextBlock Margin="10,10,10,10" Text="Beam" PointerEntered="button_OnPointerEntered"></TextBlock>
</StackPanel>
代码写好了,他可以在鼠标移入TextBlock 进入函数,可以在函数修改UWP 鼠标光标
首先使用Windows.UI.Xaml.Window.Current.CoreWindow.PointerCursor
设置或获取光标。
需要设置光标需要用Windows.UI.Core.CoreCursor
他有一些比较多用的类型,下面是他们对于代码
- Hand 点击
- Arrow 正常
- Cross 十字
- Help 帮助
- Wait 等待
- Beam 输入
于是对应界面
private void button_OnPointerEntered(object sender, PointerRoutedEventArgs e)
{
string str = (sender as TextBlock)?.Text as string;
uint n = 1;
switch (str)
{
case "Hand":
Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand, n);
break;
case "Arrow": Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, n); break;
case "Cross": Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Cross, n); break;
case "Help": Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Help, n); break;
case "Beam": Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.IBeam, n); break;
}
}
试试把代码放到工程,可以看到UWP 光标改变。
如果不知道 n 是什么,我可以说,自定义光标就是使用n,但是复杂。
很少会有需要自己做光标。如果需要自己做,请看自定义光标
移动鼠标
有时候需要把鼠标移动到一个元素上,UWP 移动鼠标和改变光标一样。
移动鼠标,设置CoreWindow.PointerPosition
在界面放一个按钮,点击他,移动鼠标
var p = new Point(Window.Current.Bounds.X + Window.Current.Bounds.Width / 2, Window.Current.Bounds.Y + Window.Current.Bounds.Height / 2);
Window.Current.CoreWindow.PointerPosition = p;
这样移动很简单,移动是屏幕坐标,不是应用坐标,需要对移动加上窗口移动
边栏推荐
- 如何在 PC 机上测试移动端的网页?
- Jenkins使用pipeline部署服务到远程服务器
- Prometheus完整安装
- .NET 6学习笔记(4)——解决VS2022中Nullable警告
- LINE Verda Programming Contest (AtCoder Beginner Contest 263) A~E 题解
- [极客大挑战 2019]HardSQL
- openEuler Xiong Wei: How do you view the SIG organization model in the open source community?
- JVM内存模型和结构详解(五大模型图解)
- 【工业数字化大讲堂 第二十一期】企业数字化能碳AI管控平台,特邀技术中心总经理 王勇老师分享,8月11日(周四)下午4点
- crm系统哪家好?好用的crm管理系统推荐
猜你喜欢
从事软件测试一年,只会基础的功能测试,怎么进一步学习?
MASA Stack 第三期社区例会
What is hardware integrated development?What are the cores of hardware integrated development?
【时序数据库InfluxDB】Windows环境下配置InfluxDB+数据可视化,以及使用 C#进行简单操作的代码实例...
How tall is the B+ tree of the MySQL index?
有什么好的开源自动化测试框架可以推荐?
.NET 6学习笔记(4)——解决VS2022中Nullable警告
不安装运行时运行 .NET 程序
JMeter notes 6 | JMeter recording agent (configuration)
50道Redis面试题,来看看你会多少?
随机推荐
重谈联想5G编码投票事件
搭建Zabbix监控系统
The difference between approach and method
一键生成 API 文档的妙招
基于CAP组件实现补偿事务与幂等性保障
ABP详细教程——模块类
openEuler Xiong Wei: How do you view the SIG organization model in the open source community?
EPIC是什么平台?
JVM内存模型和结构详解(五大模型图解)
手写flexible.js的原理实现,我终于明白移动端多端适配
Axure实现表格带滚动条
Functions and Features of Smart Home Control System
集合框架Collection与Map的区别和基本使用
WinForm(四)一种实现登录的方式
MySQL索引的B+树到底有多高?
[极客大挑战 2019]HardSQL
Redis 定长队列的探索和实践
Prometheus完整安装
mysql生成随机姓名、手机号、日期
.NET 6学习笔记(4)——解决VS2022中Nullable警告