How to disable some tabs on TabControl

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've tried

tabControl.Controls.Enabled = false;

and

tabControl.Controls.ForeColor = Color.Gray;

But neither seems to have any effect on the appearance of tabs. It also
doesn't appear to work on the desktop either.
 
I have worked around this in the past with both of the following options:
1. Remove the tabpage so it is not visible (and re-add it when appropriate)
2. Catch the tabcontrol_selectedindexchanged event and if it is for the
forbidden tabpage go back to the previous tab (requires some code to
remember the previous tabpage and a flag to prevent infinite recursion)

Cheers
Daniel
 
Ok thanks, I was hoping there a more direct approach so the user could still
see the same number of tabpages each time. I'll try your suggestions as a
workaround.

Daniel Moth said:
I have worked around this in the past with both of the following options:
1. Remove the tabpage so it is not visible (and re-add it when appropriate)
2. Catch the tabcontrol_selectedindexchanged event and if it is for the
forbidden tabpage go back to the previous tab (requires some code to
remember the previous tabpage and a flag to prevent infinite recursion)

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Tim Johnson said:
I've tried

tabControl.Controls.Enabled = false;

and

tabControl.Controls.ForeColor = Color.Gray;

But neither seems to have any effect on the appearance of tabs. It also
doesn't appear to work on the desktop either.

 
You can also place all controls in the Panel and the Panel on the Tab page.
Whenever a certain tab page need to be disabled, you can set the Panel's
enabled property to false.

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com | www.opennetcf.org


Tim Johnson said:
Ok thanks, I was hoping there a more direct approach so the user could still
see the same number of tabpages each time. I'll try your suggestions as a
workaround.

Daniel Moth said:
I have worked around this in the past with both of the following options:
1. Remove the tabpage so it is not visible (and re-add it when appropriate)
2. Catch the tabcontrol_selectedindexchanged event and if it is for the
forbidden tabpage go back to the previous tab (requires some code to
remember the previous tabpage and a flag to prevent infinite recursion)

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Tim Johnson said:
I've tried

tabControl.Controls.Enabled = false;

and

tabControl.Controls.ForeColor = Color.Gray;

But neither seems to have any effect on the appearance of tabs. It also
doesn't appear to work on the desktop either.

 
Hi all,

Good solution Alex making the whole panel disabled. This way all
controls are disabled. However, I think the end-user can think it has
total access to the tab page because the tab page is enabled and
opposite to that, all controls are disabled for him.

In my oppinion, best solution should be to make the corresponding tab
page not visible, but the method of adding and removing tabpages does
not convince me at all. Re-adding of tabpages mantains indexes inside
the tabcontrol? I think (correct me if I'm wrong...) your proposal is
adding always tabpages at runtime, being the initial situation a
tabcontrol without no tabpages at design time. Any alternative
solutions to that?

Thanks in advance.
 
Back
Top