Setting focus to a textbox control

后端 未结 7 936
隐瞒了意图╮
隐瞒了意图╮ 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:39

    Quite simple :

    For the tab control, you need to handle the _SelectedIndexChanged event:

    Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As System.EventArgs) _
      Handles TabControl1.SelectedIndexChanged
    
    If TabControl1.SelectedTab.Name = "TabPage1" Then
        TextBox2.Focus()
    End If
    If TabControl1.SelectedTab.Name = "TabPage2" Then
        TextBox4.Focus()
    End If
    

提交回复
热议问题