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.
Asked
Active
Viewed 193 times
1 Answers
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
-
Equalsk, I don't want to be able to select the tab itself. I want the tab title to be grayed out too and I can't select it. Is there any way to do so? – user5808583 Jan 19 '16 at 13:53
-
It's that last line in your question that's really confusing, it says you want to be able to click the tab but with the controls disabled. You just want the tab to be grey so it can't be selected, right? – Equalsk Jan 19 '16 at 13:58
-
Yes, it's exactly what I want – user5808583 Jan 19 '16 at 14:07
-
Let me update my answer. – Equalsk Jan 19 '16 at 14:13
-
Thank you very much Equalsk! – user5808583 Jan 19 '16 at 14:25