如果您只是需要确保在第一次加载表单时某个控件获得焦点,然后更改TabOrder
所有控件的属性(在Designer中),以便所讨论的控件为"0",其他元素也会上升从那里,'1','2'等
如果在根据某些条件显示表单时需要动态选择其他控件,请使用以下代码:
private void Form1_Load(object sender, EventArgs e) {
// You need to show the form otherwise setting focus does nothing
// (there are no controls to set focus to yet!)
this.Show()
if (someCondition == true)
control.Focus();
else
control2.Focus();
}
Run Code Online (Sandbox Code Playgroud)