5

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

Community
  • 1
  • 1
Hodaya Shalom
  • 4,327
  • 12
  • 57
  • 111

5 Answers5

11

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

dsgriffin
  • 66,495
  • 17
  • 137
  • 137
  • As I wrote, I realized that .. I want to understand what the function `Hide` does. – Hodaya Shalom Mar 20 '13 at 08:41
  • Thanks for the detailed answer, but I'll explain myself again, I want to know what the function `Hide` does in TabPage. – Hodaya Shalom Mar 20 '13 at 08:51
  • 2
    @HodayaShalom It doesn't do anything to tabPage - it is recommended not to be used. look up the visible property - http://msdn.microsoft.com/en-us/library/y6e1ah1k.aspx - it is also ' not meaningful for this control.' the same as hide() – dsgriffin Mar 20 '13 at 08:53
  • "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. – Hodaya Shalom Mar 20 '13 at 10:02
10

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.

V4Vendetta
  • 37,194
  • 9
  • 78
  • 82
2

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

Konrad
  • 509
  • 5
  • 17
0

Try this little trick;

Create your Tab Control in your Designer, then in your Form's constructor, set the following;

 this.tabReportSelection.ItemSize = new System.Drawing.Size(0, 1);
 this.tabReportInformation.Appearance = System.Windows.Forms.TabAppearance.Buttons;
 this.tabReportInformation.SizeMode = System.Windows.Forms.TabSizeMode.Fixed;

Then somewhere in your form code, use the following to show the TabPage you want;

 tabReportSelection.SelectTab("tabPageName");

It works pretty well for me.

ggrewe1959
  • 87
  • 1
  • 3
  • 12
0

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

Muhammad Saeed
  • 81
  • 3
  • 10