You will get the disable option in Tab controls, but it may
not give the actual result at what you are expecting,
TabControl.Controls[“TabName”].Enabled will work only the contents in the tab.
If you want to disable the tab’s caption and don’t want to show the tab’s
contents to the user then you need to some tricky stuff’s in WinForms. It will
not support with direct way.
1.
Enable the DrawMode property to OwnerDrawFixed
for that tab control. This is required for firing the event DrawItem, otherwise
it will not work.
2.
Disable the controls in the design mode or page
load.
Eg : tabControl1.Controls["tabPage2"].Enabled = false;
tabControl1.Controls["tabPage4"].Enabled = false;
3.
Do the given code in DrawItem event
private void
tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
TabPage
tabPage = tabControl1.TabPages[e.Index];
if
(!tabPage.Enabled)
e.Graphics.DrawString(tabPage.Text, tabPage.Font, new SolidBrush(SystemColors.GrayText), e.Bounds);
else
e.Graphics.DrawString(tabPage.Text, tabPage.Font, new SolidBrush(tabPage.ForeColor),
e.Bounds);
}
4.
While selecting that control you have to cancel
the operation. Do the code given below.
private void
tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
if
(!e.TabPage.Enabled)
e.Cancel = true;
}
