如何将 TabControl 选项卡设置为不可见
在使用 VS2005 的 C# 中,我有一个带有 7 个选项卡的 Winforms TabControl,但我希望最后一个选项卡仅在设置了某个配置选项时才可见。
如何让TabControl只显示前六个选项卡?换句话说,如何使第七个选项卡不可见?
In C# using VS2005 I have a Winforms TabControl with 7 tabs, but I want the last tab to be only visible if a certain configuration option is set.
How to make the TabControl only show the first six tabs? In other words, how do I make the seventh tab not visible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
this.tabPage2 是您的第七个选项卡页,无论您给它起什么名字。
this.tabPage2 is your 7th tabpage, whatever name you give it.
不,不可能在选项卡控件中隐藏选项卡。如果您要在运行时添加选项卡,则如果条件不满足,则不要添加第七个选项卡。
如果您在设计时完成,则在条件失败时删除该选项卡。
No its not possible to hide a tab in tabcontrol. If you are adding the tabs ar run time then dont add 7th tab if condition not satisfied.
If you done in design time then remove the tab if condtion failed.
您可以实现一个属性,
您还应该覆盖您的处置函数,
您可以将
Dispose
函数从设计器生成的代码移出到您自己的代码,设计器注意到这一点。你看到components.Dispose();
函数无法再到达tabPage进行处置,因此如果尚未处置,则需要手动处置。否则,特别是如果您多次打开窗户,就会用完窗户把手you can implement a property
you should also overwrite your disposing function,
you can move out the
Dispose
function from the designer generated code to your own code, the designer notices that. you see that thecomponents.Dispose();
function can not reach the tabPage any more for disposal, so you need to dispose it manually if it has not been disposed. otherways, especially if you are opening your window many times, you run out of window handles