How do you disable a tab

Docking/MDI for Windows Forms Forum

Posted 18 years ago by Nick Peterson
Avatar
I'm using the UIStudio TabStrip and need to disable a tab. I've tried simply setting the TabStripPage enabled property to false, but all this seems to do is disable all of the controls on that TabStripPage, still allowing the user access to that page. My goal is to completely disable the tab, preventing the user from clicking on it alltogether. Is this not possible or am I just missing something?

Comments (16)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Nick,

You can handle the SelectionChanging event and set e.Cancel to true to cancel page changes, thereby disabling the tab.


Actipro Software Support

Posted 18 years ago by JoeP - Software Design Engineer, Microsoft
Avatar
This is all well and good, but the TabStripPage doesn't look "disabled". Also, we're no longer finding the "Enabled" property for the TabStripPage. Has this been removed? How do we make the TabStripPage looked disabled?

jp

[Modified at 02/03/2006 07:06 PM]
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Joe,

Right now the Enabled property on a TabStripPage won't do anything but we can add that to the TODO list to allow for TabStripPages with an Enabled property of false to draw with a dimmed text and image appearance. We'll try and get that in on the next maintenance release for you.


Actipro Software Support

Posted 18 years ago by Mike
Avatar
I agree with Joe that overriding the selection change event is not clean. Please try and get this in the next release.

[Modified at 02/06/2006 04:11 PM]
Posted 18 years ago by Nick Peterson
Avatar
Add another one to the "need this" list.

In the mean time, this is what I'm doing, and it seems to work ok for now.

First I call my ShowTab method setting the enabled property of the tab in question. Inside this method I also changed the tab's unselectedforecolor to give it the appearance of enabled or disabled.

private void ShowTab(String tabPage, Boolean tabVisible)
{
    if (tabVisible)
    {
        tbsMain.Pages[tabPage].Enabled = true;
        tbsMain.Pages[tabPage].TabUnselectedForeColor = Color.Black;
    }
    else
    {
        if (tbsMain.SelectedPage.Key == tabPage)
        {
            tbsMain.SelectedPage = tspDetails;
        }
        tbsMain.Pages[tabPage].Enabled = false;
        tbsMain.Pages[tabPage].TabUnselectedForeColor = Color.LightGray;
    }
}
Then, when the selectionchanging event fires, if the tab being selected is supposed to be disabled, I cancel the event.

private void tbsMain_SelectionChanging(object sender, TabStripPageCancelEventArgs e)
{
    if (e.TabStripPage.Key == "tabProperties" && !e.TabStripPage.Enabled)
    {
        e.Cancel = true;
    }
}
I agree that it's not the cleanest way to handle it, and I certainly hope this is fixed in the next release.

[Modified at 02/06/2006 07:57 PM]

[Modified at 02/06/2006 08:02 PM]
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
How about this... you will be able to click on the tab but when Enabled = false, it will default to having the SelectionChanging event argument's Cancel property to true. That way you can programmatically allow the change if you set Cancel back to false in your SelectionChanging event handler.

Then also, we can add some code to the renderer to make the tab look different. Would that work for all of you?


Actipro Software Support

Posted 18 years ago by Mike
Avatar
That works for me.
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Ok, all this is now in for the next maintenance release.


Actipro Software Support

Posted 18 years ago by Nick Peterson
Avatar
Yeah, this should work for me as well.

Thanks!
Posted 18 years ago by JoeP - Software Design Engineer, Microsoft
Avatar
Works for me too....
Posted 18 years ago by Mike
Avatar
Was this feature included in the 2/16 release of 1.5? When will it be included in 2.0?
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Mike,

No it is ready for the next version 2.0 maintenance release. Another customer had some issues with the bar controls that were reported to us a couple days back so we made some changes for him to try and resolve those issues. If we get the ok on the fixes from the customer, we should be able to get the maintenance release out very soon.

[Modified at 03/01/2006 06:45 PM]


Actipro Software Support

Posted 18 years ago by Mike
Avatar
How about in the 3/7 release (2.0.61)?
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes it's in that.


Actipro Software Support

Posted 18 years ago by Mike
Avatar
I've installed the latest release but cannot get to this property for a TabPage. The product information included with this release does metnion the addition of this property but it doesn't seem to be working.

I uninstalled the previous build prior to installing this one and have also verified that the references also show the new version in my project.

FYI - I did verify that I do have a TabDisabledForeColor property.

[Modified at 03/16/2006 02:40 PM]
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Mike,

It appears we forgot to make the Enabled property browsable in the designer so that will be added for the next release. But if I run the sample project's tabstrip test form, I set the Enabled property for a page to be false (not that I changed the property to be browsable) and it turns to a dimmed color and can't be clicked.

You can do the same thing if you set the enabled property to false for a tabstrippage via code. For instance, at the end of the constructor of TabStripForm, I added this line and it worked fine:
syntaxEditorInfoTabStripPage.Enabled = false;


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.