开发者

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 pro开发者_JS百科perty 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?


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜