VB.Net Hide Tabpage

前端 未结 3 1229
小蘑菇
小蘑菇 2021-01-20 18:39

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

相关标签:
3条回答
  • 2021-01-20 19:21

    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.

    0 讨论(0)
  • 2021-01-20 19:36

    Just hide the whole TabControl by setting its Visible property

    0 讨论(0)
  • 2021-01-20 19:44

    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.

    0 讨论(0)
提交回复
热议问题