How can I disable (grey out) specific tabpage(s) of a tab control programatically in my C# form app?

219 Views Asked by At

I can't believe that disabling specific tabpages (visible but greyed out that means not clickable) is not possible in Visual Studio C# Form app. I have found just a workaround that I couldn't bring to work.(See link below) I wanted to ask this question again, because perhaps there is another solution/workaround in the meantime. How to highlight/grey-out Tabcontrol Tabpage

For just making the tab nonclickable (what is also OK for me) I have used this code, but not working

 private void tabControl1_Selecting(object sender,TabControlCancelEventArgs e)
    {
        if (!e.TabPage.Enabled)
        {
            e.Cancel = true;
        }
    }
1

There are 1 best solutions below

1
machan On BEST ANSWER

For example if you want to disable tabPage2 use this code in form load event. It will not show in intellisense but you can type.

tabPage2.Enabled = false;

Then use tab control selecting event like this

private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
   if (e.TabPageIndex < 0) return;
   e.Cancel = !e.TabPage.Enabled;
}