Setting focus to a textbox control

后端 未结 7 953
隐瞒了意图╮
隐瞒了意图╮ 2021-02-05 15:54

If I want to set the focus on a textbox when the form is first opened, then at design time, I can set it\'s tabOrder property to 0 and make sure no other form control has a tabO

7条回答
  •  一个人的身影
    2021-02-05 16:33

    I think what you're looking for is:

    textBox1.Select();
    

    in the constructor. (This is in C#. Maybe in VB that would be the same but without the semicolon.)

    From http://msdn.microsoft.com/en-us/library/system.windows.forms.control.focus.aspx :

    Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.

提交回复
热议问题