Martin
Martin

Reputation: 24316

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?

Upvotes: 5

Views: 6442

Answers (3)

MusiGenesis
MusiGenesis

Reputation: 75396

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.

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 942358

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.

Upvotes: 11

JYelton
JYelton

Reputation: 36546

Making a small project to confirm this, if you check the Visible property of any control on a tab page that is not currently selected, it will return false, because the control is not visible.

If you are trying to determine which tab page a user is currently viewing, you may be better off to check the SelectedTab or SelectedIndex property of the TabControl.

Upvotes: 0

Related Questions