当前位置:网站首页>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;
这样移动很简单,移动是屏幕坐标,不是应用坐标,需要对移动加上窗口移动
边栏推荐
- Redis的那些事:一文入门Redis的基础操作
- What is hardware integrated development?What are the cores of hardware integrated development?
- 记一次 .NET 某工控自动化控制系统 卡死分析
- 一口气拿下6个大厂offer,是什么水平
- Volatile:JVM 我警告你,我的人你别乱动
- In-depth understanding of MySQL common data types and data type selection optimization
- 进程的两种创建方式,join方法,进程间的数据隔离,队列,进程间的通信IPC机制,生产者消费者模型,守护进程,僵尸进程,孤儿进程,互斥锁
- What is test development and why is it so popular now?
- 国际土壤模型协会 International Soil Modeling Consortium-ISMC
- 如何仿造一个websocket请求?
猜你喜欢
What is test development and why is it so popular now?
[Pycharm easy to use function]
Ark: Survival Evolved Open Server Port Mapping Tutorial
JMeter笔记6 | JMeter录制(配置代理)
In-depth understanding of MySQL common data types and data type selection optimization
在 .NET MAUI 中如何更好地自定义控件
逻辑越权和水平垂直越权支付篡改,验证码绕过,接口
WPF 实现柱形统计图
Fees and inquiry methods of futures account opening exchanges
面试中老生常谈的MySQL问答集锦夯实基础
随机推荐
【燃】是时候展现真正的实力了!一文看懂2022华为开发者大赛技术亮点
A carnival of art and technology, cloud XR supports Anaya 2022 Sandbox Immersive Art Season
approach和method的区别
WPF效果第一百九十四篇之伸缩面板
.NET Community Toolkit 8.0.0 版本发布
我不写单元测试,被批了
The senior told me that the MySQL of the big factory is connected through SSH
leetcode300.最长递增子序列(动态规划)
WPF 实现柱形统计图
JMeter笔记6 | JMeter录制(配置代理)
.NET MAUI 跨平台应用开发 I|.NET MAUI 跨平台基础
Redis 定长队列的探索和实践
试试使用 Vitest 进行组件测试,确实很香。
How tall is the B+ tree of the MySQL index?
MySQL的索引你了解吗
leetcode/链表中环的入口节点
重谈联想5G编码投票事件
Jenkins使用pipeline部署服务到远程服务器
艺术与科技的狂欢,云端XR支撑阿那亚2022砂之盒沉浸艺术季
Jenkins deploys services to remote servers using pipelines