Reputation: 5075
I have TabControl
and 4 TabPages
. I need to select the second Tab programmatically!
Upvotes: 10
Views: 48514
Reputation: 331
Here is my approach, I trust someone will find it helpful, using My.Settings:
Code for the exit button/routine:
Private Sub PicClose_App_Click(sender As Object, e As EventArgs) Handles PicClose_App.Click
' Save the current active tab index, this will be used on next startup to determine on which TabPage to start
My.Settings.Main_Form_Startup_TabPage = MyTabControl.SelectedTab.TabIndex
Application.Exit()
End Sub
Code called from the Load event of the main form:
Public Sub Form_Startup_TabPage()
' Get tab index from settings, 0 has been set as default
Dim IntStartup_TabPage As Integer = My.Settings.Main_Form_Startup_TabPage
' Select the last tab used
FrmMain.TabChar_Group_Selection.SelectedIndex = IntStartup_TabPage
End Sub
Upvotes: 1
Reputation: 578
You have two ways to do it
SelectedTab:
MyTabControl.SelectedTab = MyTabPage
(The TabPage you want to select)
SelectedIndex:
MyTabControl.SelectedIndex = 1
(1 is the index of the second TabPage)
Upvotes: 28