Can you make tabs invisible, or make them have a faded look??

I am working with a windows form application. The main windows form has 3 tabs on it. Is there a way to make certain tabs invisible, and then make them visible at a later point in time? If I can't make them invisible then is it possible to make certain tabs have an Inactive look to them?
I have tried disabling tabs, and that works, however it ends up being a pretty strange user experience because the tab that is disabled looks fully functional, but of course does not work because it has been disabled.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Actually, you cannot disable tabs neither hide them. There are 2 workarounds:
Disable all controls on tab page:
Private Sub EnableControls(bEnable As Boolean, container As Control)
    For Each c As Control In container.Controls
        If c.HasChildren Then EnableControls(bEnable, c)
            c.Enabled = bEnable
        Catch ex As Exception
'not all controls has 'Enebled' property
        End Try
End Sub

Open in new window

to disable call EnableControls(False, YourTabPage)
to enable call EnableControls(True, YourTabPage)

Another way is to hold tabpages in a collection and add|remove them when need:
Private myPages As New Dictionary(Of String, TabPage)
Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    For Each tp As TabPage In tabMain.TabPages
        myPages.Add(tp.Name, tp)
End Sub

Open in new window

Now, to hide page:
Dim tp=myPages("YourPageNameHere")
If tabMain.TabPages.Contains(tp) Then
End If

Open in new window

To show:
Dim tp=myPages("YourPageNameHere")
If Not tabMain.TabPages.Contains(tp) Then
    tabMain.TabPages.Insert(YourPagePositionHere, tp)
End If

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I've always just added the Tabs to the Tab Control and then used the Remove and Insert methods shown above. Seems to work for me, but then I may be misunderstanding what you need.
Éric MoreauSenior .Net ConsultantCommented:
Hello Eric! TabPages (at least in VS2010) have not Enabled property, so I used Tag. Here is your code (shorten to functionality, your drawing is more complicated ) without wndproc subclassing
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        For i = 1 To 5
            TabControl1.TabPages.Add("Page" & i + 2)
            If i Mod 2 Then TabControl1.TabPages(i).Tag = "Disabled"
        TabControl1.DrawMode = TabDrawMode.OwnerDrawFixed
        AddHandler TabControl1.DrawItem, AddressOf TabControl_DrawItem
        AddHandler TabControl1.Selecting, AddressOf TabControl_Selecting
    End Sub

    Private Sub TabControl_Selecting(sender As Object, e As System.Windows.Forms.TabControlCancelEventArgs)
        If e.Action = TabControlAction.Selecting Then
            If e.TabPage.Tag IsNot Nothing AndAlso e.TabPage.Tag.ToString = "Disabled" Then e.Cancel = True
        End If
    End Sub

    Private Sub TabControl_DrawItem(sender As Object, e As System.Windows.Forms.DrawItemEventArgs)
        Dim tp = TabControl1.TabPages(e.Index)
        Dim br = New SolidBrush(Color.Black)
        If tp.Tag IsNot Nothing AndAlso tp.Tag.ToString = "Disabled" Then
            br = New SolidBrush(Color.Gray)
        End If
        e.Graphics.FillRectangle(New SolidBrush(SystemColors.Control), e.Bounds)
        e.Graphics.DrawString(tp.Text, TabControl1.Font, br, e.Bounds)
    End Sub

Open in new window

Éric MoreauSenior .Net ConsultantCommented:
I know that tabpages don't have the enabled property. that's the whole context of my article! the control is extended to offer one.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.