Ive seen some discussion on here about how to hide tabs in a tabcontrol but they all seem to be in C or some variant. I havent seen one for vb.net (i cant do C)
What
You just add and remove TabPages
from the TabControl through the TabPages
collection:
TabControl1.TabPages.Add(myTabPage)
and to remove it:
TabControl1.TabPages.Remove(myTabPage)
Note: Removing a TabPage
does not dispose it, it just removes it from the TabPage
collection.
Just hide the whole TabControl by setting its Visible
property
Currently, the following code block disables all the controls on that TabPage (Sets Control.Enabled = False). The tab itself is still visible and selectable from the TabControl, it is not hidden. The tab is selectable and all the elements appear disabled.
TabMyTab.Enabled = False
If you want to disable the tab similar to i.e. button.Enabled = False
which does not allow the control to be used, you will need to do something different as disabling a TabPage as in the code above disables all controls in that tab. If this is what you want, keep reading. A lot of programmers suggest using the TabControl to disallow the tab from being selected by selecting a different or the previously selected tab. This is the most effective way I know. I would implement this as follows:
Private PreviousTab As New TabPage
Private CurrentTab As New TabPage
Private Sub TabControlName_Deselected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles TabControlName.Deselected
PreviousTab = e.TabPage
End Sub
Private Sub TabControlName_Selected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles TabControlName.Selected
CurrentTab = e.TabPage
If (PreviousTab.Name <> CurrentTab.Name) And (CurrentTab.Name = UnselectableTab.Name) Then
MessageBox.Show("Tab disabled.", "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
TabControlName.SelectedTab = PreviousTab
End If
End Sub
Substitute your own values for "UnselectableTab" and "TabControlName" for your project.