0

I have a tab control with couple of tabs on it, I want to disable one of the tabs while checking a radio button on the other tab page. I can disable the controls on it by using tab.Enabled = False; But I want to know how I am able to disable the whole page from even clicking on the tab. The way I did I can select the tab still, just the controls on it are disable.

1 Answers1

0

There's no native way to disable just one tab and leave the rest working. You'll need to make your own TabControl and use the Selecting event to detect when someone is about to enter your tab and disable it.

Here's a really basic example that stops you from entering tabindex 1.

// Make your own control deriving from TabControl
class CustomTabControl : TabControl
{
    // Subscribe to the Selecting event
    public CustomTabControl()
    {
        Selecting += tabSelecting;
    }

    private void tabSelecting(object sender, TabControlCancelEventArgs e)
    {
        // You would put your own logic here to detect which tabs to disable
        // For this example I'm disabling access to tab in index 1
        if (e.TabPageIndex == 1)
        {
            e.Cancel = true;
        }
    }
}

If you want the tab to grey out you'll need to override the DrawItem even and paint the tab yourself. If I have the code for that I'll update my answer in a bit.

Edit: It seems the example for custom drawing is pretty long, but here is the tutorial I used to create my own tabs.

http://www.codeproject.com/Articles/91387/Painting-Your-Own-Tabs-Second-Edition

Equalsk
  • 7,954
  • 2
  • 41
  • 67