K
Kevin
Although lots of people described how to workaround the lack of ability
to hide and show tab pages on a tab control, I couldnt find a code
example so I made one. Create a class that inherits from the
tabcontrol and then add the following
Private htVisibleVal As New Hashtable
Private htVisibleKey As New Hashtable
Private htInvisibleKey As New Hashtable
'stores the current tabpages
Public Sub Initialise()
Dim tp As TabPage
Dim i As Integer
htVisibleVal.Clear()
htVisibleKey.Clear()
htInvisibleKey.Clear()
For i = 0 To Me.TabPages.Count - 1
htVisibleKey.Add(Me.TabPages(i), i)
htVisibleVal.Add(i, Me.TabPages(i))
Next
End Sub
'removes the tabpage from the tabpages collection and visible
hashtables and adds it to the invisible hashtable
Public Sub HideTabPage(ByVal tpIn As TabPage)
Dim tp As TabPage
Dim i As Integer = htVisibleKey(tpIn)
htVisibleKey.Remove(tpIn)
htVisibleVal.Remove(i)
htInvisibleKey.Add(tpIn, i)
Me.TabPages.Remove(tpIn)
End Sub
'moves the tabpage from the invisible hashtable to the visible one.
Then iterates through the visible hashtable
'adding them back to the tabcontrol
Public Sub ShowTabPage(ByVal tpIn As TabPage)
Dim i As Integer = htInvisibleKey(tpIn)
htInvisibleKey.Remove(tpIn)
htVisibleKey.Add(tpIn, i)
htVisibleVal.Add(i, tpIn)
Me.TabPages.Clear()
For i = 0 To htVisibleVal.Count - 1
Me.TabPages.Add(htVisibleVal(i))
Next
End Sub
call the initialise method after the windows designer has added the tab
pages to its tabpage collection. You only need to do this once.
It could probably use some exception catching but hopefully it will get
you started.
to hide and show tab pages on a tab control, I couldnt find a code
example so I made one. Create a class that inherits from the
tabcontrol and then add the following
Private htVisibleVal As New Hashtable
Private htVisibleKey As New Hashtable
Private htInvisibleKey As New Hashtable
'stores the current tabpages
Public Sub Initialise()
Dim tp As TabPage
Dim i As Integer
htVisibleVal.Clear()
htVisibleKey.Clear()
htInvisibleKey.Clear()
For i = 0 To Me.TabPages.Count - 1
htVisibleKey.Add(Me.TabPages(i), i)
htVisibleVal.Add(i, Me.TabPages(i))
Next
End Sub
'removes the tabpage from the tabpages collection and visible
hashtables and adds it to the invisible hashtable
Public Sub HideTabPage(ByVal tpIn As TabPage)
Dim tp As TabPage
Dim i As Integer = htVisibleKey(tpIn)
htVisibleKey.Remove(tpIn)
htVisibleVal.Remove(i)
htInvisibleKey.Add(tpIn, i)
Me.TabPages.Remove(tpIn)
End Sub
'moves the tabpage from the invisible hashtable to the visible one.
Then iterates through the visible hashtable
'adding them back to the tabcontrol
Public Sub ShowTabPage(ByVal tpIn As TabPage)
Dim i As Integer = htInvisibleKey(tpIn)
htInvisibleKey.Remove(tpIn)
htVisibleKey.Add(tpIn, i)
htVisibleVal.Add(i, tpIn)
Me.TabPages.Clear()
For i = 0 To htVisibleVal.Count - 1
Me.TabPages.Add(htVisibleVal(i))
Next
End Sub
call the initialise method after the windows designer has added the tab
pages to its tabpage collection. You only need to do this once.
It could probably use some exception catching but hopefully it will get
you started.