What does TabPage.Hide() do?

18,503

Solution 1

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.

Solution 2

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."

Solution 3

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.)

Share:
18,503
Hodaya Shalom
Author by

Hodaya Shalom

Updated on August 24, 2022

Comments

  • Hodaya Shalom
    Hodaya Shalom over 1 year

    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:

    enter image description here

  • Hodaya Shalom
    Hodaya Shalom about 11 years
    As I wrote, I realized that .. I want to understand what the function Hide does.
  • Hodaya Shalom
    Hodaya Shalom about 11 years
    Thanks for the detailed answer, but I'll explain myself again, I want to know what the function Hide does in TabPage.
  • dsgriffin
    dsgriffin about 11 years
    @HodayaShalom It doesn't do anything to tabPage - it is recommended not to be used. look up the visible property - msdn.microsoft.com/en-us/library/y6e1ah1k.aspx - it is also ' not meaningful for this control.' the same as hide()
  • Hodaya Shalom
    Hodaya Shalom about 11 years
    "Use what I wrote above instead to achieve what you want." I explained already in question, I'm not trying to get it to work with the function. I realized myself that it is not possible! All I need is not a suggestion what to do (it already did), but an explanation of the Hide function. Thanks anyway.