title: Disable Tab Control when pressing Button VB.NET
body: <p>I would like to ask if how could possibly disable tabs in tabcontrol.</p>
  
  <p>This is what the codes looks like when disable:</p>
  
  <pre><code> 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
  </code></pre>
  
  <ul>
  <li>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.</li>
  </ul>
  
  <p>See this code:</p>
  
  <pre><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)
      Next
  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
  </code></pre>
  
  <p>Is there anyway that I could possibly disable a tab while clicking a button?</p>
  
  <p>Let me know!</p>
  
  <p>Thanks,</p>
  
  <p>Regards,
  Alvin</p>