我有TabControl
和4 TabPages
。我需要以编程方式选择第二个Tab!
答案 0 :(得分:12)
你有两种方法可以做到这一点
SelectedTab:
MyTabControl.SelectedTab = MyTabPage
(您要选择的标签页)
的SelectedIndex:
MyTabControl.SelectedIndex = 1
(1是第二个TabPage的索引)
答案 1 :(得分:0)
这是我的方法,我相信有人会发现它有用,使用My.Settings:
退出按钮/例程的代码:
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
从主窗体的Load事件调用的代码:
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