的WinForms C# - 设置焦点的TabPage的第一子控件 [英] Winforms c# - Set focus to first child control of TabPage
问题描述
说我有一个文本框
嵌套在的TabControl
。
当加载窗体,我想重点放在文本框
(默认焦点设置为的TabControl
)。
When the form loads, I would like to focus on that Textbox
(by default the focus is set to the TabControl
).
简单地调用 textbox1.focus()
在加载
表格的事件似乎并没有工作。
Simply calling textbox1.focus()
in the Load
event of the form does not appear to work.
我已经能够通过执行以下操作重点是:
I have been able to focus it by doing the following:
private void frmMainLoad(object sender, EventArgs e)
{
foreach (TabPage tab in this.tabControl1.TabPages)
{
this.tabControl1.SelectedTab = tab;
}
}
我的问题是:
有没有更优雅的方式来做到这一点?
Is there a more elegant way to do this?
推荐答案
下面是解决方案:
private void frmMainLoad(object sender, EventArgs e)
{
ActiveControl = textBox1;
}
最好的问题将然而是为什么......我不完全知道这个问题的答案之一。
The better question would however be why... I'm not entirely sure what the answer to that one is.
编辑:我怀疑这是值得做的事实,无论是形式,和的TabControl是容器,但我不知道
I suspect it is something to do with the fact that both the form, and the TabControl are containers, but I'm not sure.
这篇关于的WinForms C# - 设置焦点的TabPage的第一子控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!