Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i disable a tab, so that the user cannot change to it?

Tags:

c#

tabs

winforms

I want to make a quiz, which goes through the questions, keeping in mind that while question 1 is being used, the others are disabled. Once the Next button is clicked it should change directly to Q2, disabling Q1 and so on.

How do I make it disable the previous tab and keep the current one enabled after the Next button is clicked?

How do I keep the other tabs disabled?

like image 558
Oliver Avatar asked Apr 18 '13 06:04

Oliver


1 Answers

As stated previously tabs can be selected by index.

So as before, let's disable all other tabs:

foreach(TabPage tab in tabControl.TabPages)
{
    tab.Enabled = false;
}
(tabControl.TabPages[0] as TabPage).Enabled = true;

Now the way to prevent navigating to any other tab is simple:

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

The only downside is that they will appear selectable, meaning they are not grayed out. You would have to do this yourself if you want the look to appear unavailable as well.

like image 179
Jackdaw Avatar answered Sep 28 '22 23:09

Jackdaw