title: C# .NET: The TabPage of TabControl disabled/enabled implementation
body: <p>I have found some implementation of the Enabled property for tabPages, since the implementation for it in the UI is hidden, but I do not know how to use it. It might strike as a stupid question, but I really just started with c# and the .net platform. I want to take a variable from the first form, which is a login form that sends a true value if one checkbox is checked or false if it's not, and if it is true, login as an admin that has the privillege to access all the tabs, but if it is false, a user will be restricted acces from some of the tabs. I do not know how to restrict access to these tabs, or allow it. The code is as follows:</p>
  
  <p>Code for the constructor of the form:</p>
  
  <pre><code>public Form1()
  {
  InitializeComponent();
  
  this.tabControl1.DrawMode = 
  TabDrawMode.OwnerDrawFixed;
  this.tabControl1.DrawItem += 
  new DrawItemEventHandler(DisableTab_DrawItem);
  this.tabControl1.Selecting += 
  new TabControlCancelEventHandler(DisableTab_Selecting);
  }
  </code></pre>
  
  <p>The function which draws the tab pages:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Draw a tab page based on whether it is disabled or enabled.
  /// &lt;/summary&gt;
  /// &lt;param name="sender"&gt;&lt;/param&gt;
  /// &lt;param name="e"&gt;&lt;/param&gt;
  private void PageTab_DrawItem(object sender, DrawItemEventArgs e)
  {
  TabControl tabControl = sender as TabControl;
  TabPage tabPage = tabControl.TabPages[e.Index];
  
  if (tabPage.Enabled == false)
  {
  using (SolidBrush brush = 
  new SolidBrush(SystemColors.GrayText))
  {
  e.Graphics.DrawString(tabPage.Text, tabPage.Font, brush, 
  e.Bounds.X + 3, e.Bounds.Y + 3);
  }
  }
  else
  {
  using (SolidBrush brush = new SolidBrush(tabPage.ForeColor))
  {
  e.Graphics.DrawString(tabPage.Text, tabPage.Font, brush, 
  e.Bounds.X + 3, e.Bounds.Y + 3);
  }
  }
  }
  </code></pre>
  
  <p>The event handler that prevents the tab from being selected if it is disabled:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Cancel the selecting event if the TabPage is disabled.
  /// &lt;/summary&gt;
  /// &lt;param name="sender"&gt;&lt;/param&gt;
  /// &lt;param name="e"&gt;&lt;/param&gt;
  private void PageTab_Selecting(object sender, TabControlCancelEventArgs e)
  {
  if (e.TabPage.Enabled == false)
  {
  e.Cancel = true;
  }
  }
  </code></pre>
  
  <p>The said variable and the decisional statement:</p>
  
  <pre><code> int cont = Login.accountType; //the variable from the first tab, that decides whether the account is admin type or client type
          //the variable is public static int in the first form
  
          if (cont == 1)
          {
              //display all the tabs, because we logged in as admin
          }
          else if(cont == 0)
          {
              //disable the tabs that we do not want the client to access
          }
  </code></pre>