This would seem like a straight forward Visible = True or False situation. I use TabControls regularly, but I have to say I have never come across a situation where I needed to hide a TabPage(make it not visible).
The Property Visible is not meaningful for this control (this is straight from MSDN). Although in DEBUG mode you can see this property in the object tree (but it is set to FALSE no matter what). The property Hide only hides the controls on the specified TabPage, not the TabPage itself. If you Hide the TabPage the controls will be hidden, interestingly, if you move from that page and then move back to the TabPage that invoked .Hide(), the controls will then be visible.
I believe the only way to facilitate "visible/non-visible" is by removing the TabPage from the TabPages collection when you need to make it not visible and then adding it back in when the TabPage is to be visible.
The link below has a solution that should give you a good starting point – you will need to manage the remove/add activities with some additional code.
https://social.msdn.microsoft.com/Forums/windows/en-US/89053adf-7875-4db9-b328-460a7b1f97c0/how-to-remove-hide-tabpage-from-a-tabcontrol-using-vb-net-c-net
The following is a suggestion, moving TabPages between two or more TabControls to maintain the original collect isn't necessary. And the design considerations given below in Solution 2 do address some of the problems you face. To solve the specific problem you state without questioning the objective I would do something similar to the following code. Note this has the mechanism to remove-store and add-back. The DOUBLECLICK method is used for demo purposes. You can add this to your project, rebuilt, add the control to a form and explore.
Public Class MyTabControl
Inherits TabControl
#Region "DELEGATES_EVENTS"
Public Event HasError(ByVal sender As Object, ByVal e As EventArgs)
#End Region
#Region "VARS"
Dim RemoveTabs As List(Of TabPage)
Dim _lastRemoveException As Exception
#End Region
#Region "CONSTRUCTORS_DESTRUCTORS"
Public Sub New()
RemoveTabs = New List(Of TabPage)
End Sub
#End Region
#Region "SUBS_FUNCS"
Private Sub OnError(ByVal e As Exception)
_lastRemoveException = e
RaiseEvent HasError(Me, EventArgs.Empty)
End Sub
Public Function GetLastExcceptio() As Exception
Return _lastRemoveException
End Function
Public Function RemoveCurrentTab(ByVal tp As TabPage) As Boolean
Dim result As Boolean
Try
TabPages.Remove(tp)
RemoveTabs.Add(tp)
result = True
Catch ex As Exception
OnError(ex)
End Try
Return result
End Function
Public Function AddTabBack(ByVal title As String) As Boolean
Dim result As Boolean
Try
If Not String.IsNullOrEmpty(title) Then
For Each tp As TabPage In RemoveTabs
If String.Compare(tp.Text, title) = 0 Then
RemoveTabs.Remove(tp)
TabPages.Add(tp)
result = True
Exit For
End If
Next
End If
Catch ex As Exception
OnError(ex)
End Try
Return result
End Function
#End Region
#Region "CONTROL_EVENTS"
Private Sub MyTabControl_DoubleClick(sender As Object, e As EventArgs) Handles Me.DoubleClick
RemoveCurrentTab(Me.SelectedTab)
End Sub
#End Region
End Class
regs
ron O.