Hide all but one tab pages by default

johncassell

Well-known member
Joined
Jun 10, 2007
Messages
120
Location
Redcar, England
Programming Experience
Beginner
Hi there,

could someone tell me the best way to do the following:

I have a tabcontrol with 8 tabs. When my form loads, I would like all but the first tab to be hidden.

I could do myself but it would be like

VB.NET:
        TabControl1.TabPages.Remove(CleaningTab)
        TabControl1.TabPages.Remove(HeatingTab)

and I thought surely there is a better way?

Thanks for any help

John
 
Tabcontrol doesn't support hiding the tabs, so you have to maintain a private collection of the tabs and add/remove them to control as needed. Here is an example (assumed you have created the tabs in Designer):
VB.NET:
    Private hiddentabs As New List(Of TabPage)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
        For Each tab As TabPage In TabControl1.TabPages
            hiddentabs.Add(tab)
        Next
        showtab(0)
    End Sub

    Sub showtab(ByVal index As Integer)
        TabControl1.TabPages.Clear()
        TabControl1.TabPages.Add(hiddentabs(index))
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button2.Click
        showtab(1)
    End Sub
 
Tabpages can't be disabled. There is another option in locking the SelectedTab/-Index.
 
Back
Top