标签页上不可见的控件(选项卡控件)返回 Visible = false
我在 Windows 窗体中有一个选项卡控件。除了下面的示例之外,它运行得很好。当我选择 tabpage2
时,tabpage1
上的所有控件都将其 visible
属性返回为 FALSE,这实际上是不正确的,因为它们都设置为 可见=假
。
我想这是因为 tabpage1
设置为 visible = false
所以所有子控件都继承 FALSE。
当然,如果选择了 tabpage1
,则所有控件都会返回可见属性的正确值。
必须有一个解决办法。有人有解决办法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Visible 属性有点特殊,它的 getter 不会返回您分配的值。它告诉您该控件是否实际上可见。如果将其放置在未选择的选项卡页上,则情况并非如此。这是设计使然。
不支持获取实际的“打算可见”状态。您可以从 GetState(2) 中获取它,但这是一个内部方法。如果你真的很绝望,那么你可以使用反射。但正确的方法是自己跟踪。
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.
由于面板的
Visible
属性未按照您期望的方式运行,请尝试将面板的Tag
属性设置为某项或其他,并使用它来确定是否使验证失败。Since the
Visible
property of your panel is not behaving in the way you expect, try setting the Panel'sTag
property to something or other instead, and use that to determine whether or not to fail the validation.制作一个小项目来确认这一点,如果您检查当前未选中的选项卡页上任何控件的
Visible
属性,它将返回 false,因为该控件是不可见。如果您尝试确定用户当前正在查看哪个选项卡页,则最好检查 TabControl 的
SelectedTab
或SelectedIndex
属性。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
orSelectedIndex
property of the TabControl.