标签页上不可见的控件(选项卡控件)返回 Visible = false

发布于 2024-10-11 13:33:53 字数 352 浏览 5 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如痴如狂 2024-10-18 13:33:53

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.

一桥轻雨一伞开 2024-10-18 13:33:53

由于面板的 Visible 属性未按照您期望的方式运行,请尝试将面板的 Tag 属性设置为某项或其他,并使用它来确定是否使验证失败。

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.

拿命拼未来 2024-10-18 13:33:53

制作一个小项目来确认这一点,如果您检查当前未选中的选项卡页上任何控件的 Visible 属性,它将返回 false,因为该控件是可见。

如果您尝试确定用户当前正在查看哪个选项卡页,则最好检查 TabControl 的 SelectedTabSelectedIndex 属性。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文