vb.net 如何选择标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31991325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:10:02  来源:igfitidea点击:

How to Select Tab

vb.nettabcontroltabpage

提问by raed

I have TabControland 4 TabPages. I need to select the second Tab programmatically!

我有TabControl和 4 TabPages。我需要以编程方式选择第二个选项卡!

回答by Amal

You have two ways to do it

你有两种方法可以做到

  1. SelectedTab:

    MyTabControl.SelectedTab = MyTabPage(The TabPage you want to select)

  2. SelectedIndex:

    MyTabControl.SelectedIndex = 1(1 is the index of the second TabPage)

  1. 所选标签:

    MyTabControl.SelectedTab = MyTabPage(您要选择的 TabPage)

  2. 选定索引:

    MyTabControl.SelectedIndex = 1(1为第二个TabPage的索引)

回答by vicsar

Here is my approach, I trust someone will find it helpful, using My.Settings:

这是我的方法,我相信有人会发现它有用,使用 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:

从主窗体的 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