我正在创建一个自定义控件。在该控件上我有大约 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/