【问题标题】:Difference between .ActiveControl and .Focus and what each does.ActiveControl 和 .Focus 之间的区别以及各自的作用
【发布时间】:2018-09-08 18:17:49
【问题描述】:

您好,我正在学习 C#,并将其添加到我的代码中

InitializeComponent();
this.ActiveControl = txtUsername;
txtUsername.Focus();

this.ActiveControl.Focusdo 有什么作用和有什么区别

感谢您的宝贵时间

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    他们都可以有效地做同样的事情。一个需要可见元素,而另一个不需要。这可用于在表单出现时将光标输入置于txtUsername

    this.ActiveControl = txtUsername;
    

    如果txtUsername 控件可见,这将执行相同的操作。

    txtUsername.Focus();
    

    关键是元素必须是可见的,Focus() 方法才能工作。请参阅this 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-29
      • 2017-04-11
      • 2018-07-05
      相关资源
      最近更新 更多