Alvin Quezon Alvin Quezon - 1 year ago 243 Question

Disable Tab Control when pressing Button VB.NET

I would like to ask if how could possibly disable tabs in tabcontrol.

This is what the codes looks like when disable:

Public Sub TabControl1_Selecting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Selecting
If e.TabPageIndex = 3 Then
e.Cancel = True
End If
End Sub

  • This code only disable while you load the form
    I was trying to convert a code from c# however it doesn't work as I expected.

See this code:

Public Sub EnableTabs(ByVal Page As TabPage, ByVal bolFlag As Boolean)
EnableControls(Page.Controls, bolFlag)
End Sub
Private Sub EnableControls(ByVal Ctrls As Control.ControlCollection, ByVal bolFlag As Boolean)
For Each Ctrl As Control In Ctrls
Ctrl.Enabled = bolFlag
EnableControls(Ctrl.Controls, bolFlag)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'I have problems with this line
EnableTabs(TabControl1.TabPages(TabControl1.SelectedIndex) = 0, False)
End Sub

Is there anyway that I could possibly disable a tab while clicking a button?

Let me know!




Try this:

Private Sub Button_Click( sender As Object,  e As EventArgs) Handles Button.Click
    Dim tabPage As TabPage

    For Each tabPage In TabControl1.TabPages
        If tabPage.Text ="TabPage1"
            tabPage.Enabled =False
        End If
End Sub


Private Sub Button1_Click( sender As Object,  e As EventArgs) Handles Button1.Click
        TabControl1.TabPages(0).Enabled =false
End Sub