I want to hide TabPage from TabControl.
I tried this way:
MyTabControls.TabPages[1].Hide();
It does not hide.
So I searched and saw that should delete it and recreate when you want to: How to hide TabPage from TabControl
In this case, what is the Hide
function doing at all?
Screenshot:
Sadly, you cannot do as you wish. You have to add and remove tabs and re-add them if you want that effect.
Try using this kind of syntax:
theTabControl.TabPages.Remove(tabPageA);
Then to re-add:
theTabControl.TabPages.Add(tabPageA);
Hide() - Hiding the control is equivalent to setting the Visible property to false. After the Hide method is called, the Visible property returns a value of false until the Show method is called.
Why you might use it - You might use Show()
or Hide()
when you know the value and use Visible
when you take the visibility in as a parameter, although I would personally tend to always use Visible
.
What it will do in this case - In this case it is useless and will not do anything. Just like Visible(), the following applies to it:
"TabPage controls are constrained by their container, so some of the properties inherited from the Control base class will have no effect, including Top, Height, Left, Width, Show, and Hide."
The reason is stated on MSDN as
TabPage controls are constrained by their container, so some of the properties inherited from the Control base class will have no effect, including Top, Height, Left, Width, Show, and Hide.
The tabs in a TabControl are part of the TabControl but not parts of the individual TabPage controls. Members of the TabPage class, such as the ForeColor property, affect only the client rectangle of the tab page, but not the tabs. Additionally, the Hide method of the TabPage will not hide the tab. To hide the tab, you must remove the TabPage control from the TabControl.TabPages collection.
As the TabPage
class is derived from the Control
class it has to have at least the methods Control
has. So the Hide()
function cannot be removed although it has no effect. It's not there because it does something but because of the relation to the Control
class.
(Don't ask me why it has no effect. I would like to just Hide()
my tabs as well.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With