c# - 根据控件动态改变光标

标签 c# .net user-controls

我正在创建一个自定义控件。在该控件上我有大约 20 个子控件。当我在用户控件上移动光标时,我希望光标根据其移动的子控件进行更改。

例如:

User Control
--Control 1 : if(Condition 1) { Mouse - Wait } else { Mouse - Default }
--Control 2 : if(Condition 1) { Mouse - Hand } else { Mouse - Default }
--Control 3 : Mouse - Default

......等等。

有什么方法可以确定用户控件的 MouseMove 事件我正在哪个子控件上移动,以便我可以在单个事件中更改光标。

最佳答案

您不需要依赖事件,可以使用给定控件的Cursor Property。例如,如果您有三个文本框,您可以在“设计 View ”上的“属性框”中更改此属性,或者只写:

textBox1.Cursor = Cursors.WaitCursor;
textBox2.Cursor = Cursors.Hand;
textBox3.Cursor = Cursors.Default;

在每个文本框中“输入”时,光标将显示给定的形状。

关于c# - 根据控件动态改变光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18695165/

相关文章:

c# - 使 CollectionViewSource 无效

c# - 如何正确解析从 GSM 模块收到的响应数据?

c# - ImageResizer - 转换 PSD 文件时出错 - System.ArgumentException : Parameter is not valid

.net - 将 ConnectionString 保留在 LINQ 设计器文件中

xaml - 为什么我的 DependencyProperty 不可访问?

c# - 更改用户控件上的光标

c# - 不明确的扩展方法调用

c# - 实现 IEnumerable<T> 数据结构

c# - 在库的异步方法中总是使用 'async' 和 'await' 关键字?

asp.net - 使用户控件可见时出现 javascript 错误 "object expected "