Posted by: Sourav | June 1, 2015

Set the focus on textbox controls on tab pages inside of tab control on form startup as well as when clicked on tab page,VB.Net


 If textbox1 is on that tab page of tour tab control which you want to focus on form startup

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Me.Show()
    Application.DoEvents()
    TextBox1.Focus()
End Sub

If you don’t do the Me.Show(), the form will not be displayed until the load event is complete.

For the tab control, handle the _SelectedIndexChanged event:
Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As System.EventArgs) _
  Handles TabControl1.SelectedIndexChanged

    If TabControl1.SelectedTab.Name = “TabPage2” Then
        TextBox2.Focus()
    End If
    If TabControl1.SelectedTab.Name = “TabPage3” Then
        TextBox3.Focus()
    End If

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: