I am using a TabControl
within a form designed in C#, it TabControl
has two Tabs and I need to be able to hide one and/or show it depending on a state that arrives as a parameter from another form. I can't find a property of type Visible
or in any case Enabled
.
Is there a way to hide a tab inside a TabControl or at least disable it?
Thank you very much
Winfoms tabs don't have property
Visible
, you have to remove it, if I remember correctly it's done by:Edit:
Here is an example on the microsoft website
You can occupy the parent property, where to hide the tabitem you assign a null parent
And to show it you assign the tab control in which it will be found
In principle, the TabControl of Windows Forms does not allow to show / hide a tab. What you can do is delete it although you would lose the controls of that tile.
One way to do it would be to save the TabPage type controls that you have marked as invisible in an array so that you can add them again when you make them visible.
I hope you don't mind me writing code for a control that does just this, descends from the TabControl, and keeps a list of invisible controls to display later. The other array (arrBoolPagesVisible) is used to hold the indexes and insert the controls in the same place they were at the beginning.
By passing the index of the tab you want to show/hide to the ShowTab method of this control, you'll get the result you're looking for.
An example to remove and add
TabPages
to atabControl
:What you can do is place
Enable = false
everything you have inside a tab, move it true and false, the end user will see it but he will not be able to use it.//Create delete Array and counter tabs
It is essential to add the using System.Collections;