当前位置: 首页 > news >正文

WinUI3入门11:改变鼠标形状 设置光标

初级代码游戏的专栏介绍与文章目录-CSDN博客

我的github:codetoys,所有代码都将会位于ctfc库中。已经放入库中我会指出在库中的位置。

这些代码大部分以Linux为目标但部分代码是纯C++的,可以在任何平台上使用。

源码指引:github源码指引_初级代码游戏的博客-CSDN博客

C#是我多年以来的业余爱好,新搞的东西能用C#的就用C#了。


        前面我们做了可以用鼠标改变比例的SplitPanel,按照我们以前的习惯,这种情景应该使用SizeWestEast光标,就是左右箭头。

        通常很容易设置控件/窗口的光标(鼠标形状),设置一个属性即可。然而,WinUI3里面做这件事有些麻烦,因为控件的光标属性ProtectedCursor是保护的。

目录

一、创建控件的子类,暴露受保护的ProtectedCursor

二、替换xaml控件名称

三、代码设置光标

四、常用光标


一、创建控件的子类,暴露受保护的ProtectedCursor

        为此,首先我们需要继承一个类,然后在新的类里面操作光标属性,当然,只需要把光标属性暴露出来就可以了:

        首先新建一个类:

        主要代码替换掉: 

	public class PanelBar : Microsoft.UI.Xaml.Controls.Grid{public InputCursor Cursor{get => ProtectedCursor;set => ProtectedCursor = value;}}

        注意我是继承自Grid的。原来我用的控件是Border啊,为什么不用Border呢?因为Border是个密封类,不能被继承。幸好我换成Grid以后一切正常,用到的属性都支持。

二、替换xaml控件名称

			<!-- 分隔条 --><local:PanelBar Grid.Column="1" x:Name="border_split" BorderBrush="Gray" BorderThickness="3" Margin="0,2,0,2" />

        改动的仅仅是:

        原来是“Border”,替换即可。后面的属性Grid都支持。

三、代码设置光标

        简简单单一句:

			border_split.Cursor = Microsoft.UI.Input.InputSystemCursor.Create(Microsoft.UI.Input.InputSystemCursorShape.SizeWestEast);

四、常用光标

        枚举值InputSystemCursorShape表示系统自带光标:

NameValueDescription
Arrow0

A standard arrow pointing left-upward (northwest).

Cross1

A crosshair.

Hand3

A hand.

Help4

An arrow pointing left-upward (northwest) with a question mark.

IBeam5

An "I"-shape, typically used for text insertion and selection.

SizeAll6

Crossed arrows pointing north, south, east, and west, typically used for resizing.

SizeNortheastSouthwest7

A dual arrow pointing right-upward and left-downward, typically used for element sizing.

SizeNorthSouth8

A dual arrow pointing upward and downward, typically used for vertical sizing.

SizeNorthwestSoutheast9

A dual arrow pointing left-upward and right-downward, typically used for element sizing.

SizeWestEast10

A dual arrow pointing left and right, typically used for horizontal sizing.

UniversalNo11

A red circle with 45-degree diagonal line from upper left to lower right, typically used to indicate an action that cannot be performed.

UpArrow12

An arrow pointing up.

Wait13

An animated, cycling cursor, typically used to indicate that an element or behavior is busy and cannot respond.

Pin14

A hand with a pin symbol.

Person15

A hand with a person symbol.

AppStarting16

The cursor that appears when an app starts, typically used to indicate something is loading but the UI can handle input.

        Arrow是默认的箭头光标,Size开头的是调整大小的光标,Hand是个手,Help是箭头旁边带个问号,Wait是等待光标。 


(这里是文档结束)

http://www.lryc.cn/news/574697.html

相关文章:

  • 鸿蒙应用开发中的状态管理:深入解析AppStorage与LocalStorage
  • 基于Qt C++的影像重采样批处理工具设计与实现
  • jenkinsfile调用groovy
  • 服务器安装指南
  • 从iOS到Flutter:我的转型之路与技术成长启示
  • Redis哈希表Rehash全解析:扩容缩容背后的渐进式智慧
  • 一种集成统计、视觉和基于规则方法的新型可解释医学图像分类人工智能框架|文献速递-最新论文分享
  • ffmpeg下载地址
  • wpf单文件打包还有 一些dll打包不进去?
  • 基于单片机的语音控制设计(论文)
  • PYTHON从入门到实践2-环境配置与字符串打印用法
  • 【开源项目】比 PyInstaller 更方便:图形界面打包 Python 脚本的体验
  • linux nginx更换域名证书
  • Ubuntu服务器中MySQL如何进行主从复制
  • 解锁阿里云AnalyticDB:数据仓库的革新利器
  • 支持向量机(SVM)python语言版本
  • 从0开始学习R语言--Day31--概率图模型
  • FPGA基础 -- Verilog 验证平台之 **cocotb 验证 `阶乘计算模块(factorial)` 的例子**
  • 洛谷P1092 [NOIP 2004 提高组] 虫食算
  • 基于DE1-SoC的My_First_oneAPI(一)
  • SpringBoot 3.0 - 自定义注解+拦截器+Redis 解决接口幂等性
  • 【apache-maven3.9安装与配置】
  • 从虚拟机角度解释python3相对导入问题(下)
  • 轻量化实物建模革命:WebGL如何实现复杂模型的高效加载与交互
  • ​CentOS 7 单用户模式重置 root 密码完整指南
  • 新中国风通用读书颂词分享PPT模版
  • JS核心操作符:从基础到ES6+
  • (ICML-2023)BLIP-2:使用冻结图像编码器与大型语言模型的语言-图像预训练引导方法
  • SQL Server 查询数据库及数据文件大小
  • 使用 spark-submit 运行依赖第三方库的 Python 文件