What does TabPage.Hide () do?

I want to hide TabPage from TabControl.

I tried this way:

MyTabControls.TabPages[1].Hide(); 

He does not hide.

So, I searched and saw that I had to delete it and recreate it whenever you want: How to hide TabPage from TabControl

In this case, what does the Hide function generally do?

Screenshot:

enter image description here

+4
source share
5 answers

The reason is listed on MSDN as

TabPage elements are limited by their container, so some of the properties inherited from the Control base class will not have an effect, including Top, Height, Left, Width, Show and Hide.

TabControl tabs are part of TabControl, but are not part of individual TabPage controls. Members of the TabPage class, such as the ForeColor property, only affect the client’s rectangle in the page tab, not the tabs. In addition, the Hide TabPage method will not hide the tab. To hide the tab, you must remove the TabPage control from the TabControl.TabPages collection.

+8
source

Unfortunately, you cannot do what you want. You must add and remove tabs and re-add them if you want to get this effect.

Try using the following 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 calling the Hide method, the Visible property returns false until the Show method is called.

Why you can use it . You can use Show() or Hide() when you know the value and use Visible when you see visibility as a parameter, although I personally tend to always use Visible .

What will he do in this case . In this case, it is useless, but will do nothing . Just like Visible () , the following applies to it:

"TabPage elements are limited by their container, so some properties inherited from the Control base class will not have an effect, including Top, Height, Left, Width, Show and Hide."

+9
source

Since the TabPage class TabPage derived from the Control class, it must have at least Control methods. Thus, the Hide() function cannot be removed, although it does not work. This is not so because it does something, but because of its relation to the Control class.

(Don't ask me why this doesn't work. I would just like to Hide() my tabs.)

+1
source

Try this little trick;

Create your tab control in your constructor, and then set the following in your form designer:

  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 desired TabPage tab.

  tabReportSelection.SelectTab("tabPageName"); 

This works very well for me.

0
source

TabPage elements are limited by their container, so some properties inherited from the Control base class will not have an effect, including Top, Height, Left, Width, Show and Hide. The tabs in TabControl are part of TabControl, but they are not parts of individual TabPage controls. Members of the TabPage class, such as the ForeColor property, affect only the client’s rectangle in the tab, and not the tabs. In addition, the Hide TabBage method does not hide the tab. To hide the tab, you must remove the TabPage control from the TabControl.TabPages collection.

0
source

All Articles