简体   繁体   English

Controls.add-> Controls.clear-> Controls.add自动将焦点设置为最后添加的控件吗?

[英]Controls.add -> Controls.clear -> Controls.add automatically set focus the last added control?

I have code like below. 我有下面的代码。

When the form is loaded, the textBox2 appears automatically selected and in focus. 加载表单后,textBox2会自动选中并处于焦点状态。

The calling sequence has to be like below. 调用顺序必须如下所示。 It would not be reproduced otherwise. 否则将不会复制。

Why's that? 为什么?

this.Controls.Add(this.textBox1);
this.Controls.Clear();
this.Controls.Add(this.textBox2);

The code is just an example of the real life scenario where controls are dynamically loaded. 该代码只是动态加载控件的真实场景的示例。

Thanks, 谢谢,

If you only have the textBox2 control on your form, there's only one place the focus can be. 如果窗体上只有textBox2控件,则焦点只能放在一个位置。 If you want to set the focus order of your controls, use the TabIndex property. 如果要设置控件的焦点顺序,请使用TabIndex属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM