Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controls on a tabpage (tab control) that's not visible return Visible = false

I have a tab control in a windows form. It's working great, except for the following example. When I have tabpage2 selected, all controls on tabpage1 return their visible property as FALSE which actually is untrue because they are all set to visible = false.

I suppose it's because the tabpage1 is set to visible = false so all child controls inherit FALSE.

Of course if tabpage1 is selected, then all controls return the correct value for the visible property.

There must be a work around. Does anyone have a solution?

like image 501
Martin Avatar asked Jan 13 '11 16:01

Martin


People also ask

How do I hide my tabPage?

To hide a tab: tabControl. TabPages. Remove(tabPage);

What is tab control in Visual Studio?

Windows TabControl is a useful control that allows you display multiple dialogs tabs on a single form by switching between the tabs. A tab acts as another Form that can host other controls. Figure 1 shows an example of TabControl in Visual Studio . NET, which allows you to switch among multiple files using the tabs.

How do I select a tabPage in TabControl in VB net?

To select a tab page on the form, first click its tab, then click its body. In the top combo box of the Properties window, select the name of the desired property page. On the form, click the tab control. In the Properties window, click the TabPages field and click its ellipsis button.

How do I turn off tabPage in TabControl?

You can simply use: tabPage. Enabled = false; This property is not shown, but it works without any problems.


2 Answers

The Visible property is a bit special, its getter doesn't return the value you assigned. It tells you if the control is actually visible. Which it is not if it is placed on a tab page that isn't selected. This is by design.

Getting the actual "intends to be visible" state isn't supported. You'd get it out of GetState(2) but that's an internal method. If you're really desperate then you could use Reflection. But the proper way is to just keep track of it yourself.

like image 69
Hans Passant Avatar answered Sep 26 '22 02:09

Hans Passant


Since the Visible property of your panel is not behaving in the way you expect, try setting the Panel's Tag property to something or other instead, and use that to determine whether or not to fail the validation.

like image 45
MusiGenesis Avatar answered Sep 25 '22 02:09

MusiGenesis