如何从 TabControl 中隐藏 TabPage
如何在 WinForms 2.0 中从 TabControl 中隐藏 TabPage?
How to hide TabPage from TabControl in WinForms 2.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何在 WinForms 2.0 中从 TabControl 中隐藏 TabPage?
How to hide TabPage from TabControl in WinForms 2.0?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(22)
不,这不存在。 您必须删除该选项卡并在需要时重新添加它。 或者使用不同的(第 3 方)选项卡控件。
No, this doesn't exist. You have to remove the tab and re-add it when you want it. Or use a different (3rd-party) tab control.
用于隐藏 TabPage 的代码片段
用于显示 TabPage 的代码片段
Code Snippet for Hiding a TabPage
Code Snippet for Showing a TabPage
我意识到这个问题很旧,接受的答案也很旧,但是......
至少在.NET 4.0中......
隐藏选项卡:
将其放回去:
TabPages
比用于此的控件
。I realize the question is old, and the accepted answer is old, but ...
At least in .NET 4.0 ...
To hide a tab:
To put it back:
TabPages
works so much better thanControls
for this.Tabpages 上还没有实现 Visiblity 属性,也没有 Insert 方法。
您需要手动插入和删除标签页。
这是同样的解决方法。
http://www.dotnetspider.com/resources/18344-Hiding -显示-Tabpages-Tabcontrol.aspx
Visiblity property has not been implemented on the Tabpages, and there is no Insert method also.
You need to manually insert and remove tab pages.
Here is a work around for the same.
http://www.dotnetspider.com/resources/18344-Hiding-Showing-Tabpages-Tabcontrol.aspx
变体 1
为了避免视觉 klikering,您可能需要使用:
或
删除选项卡页:
添加选项卡页:
在特定位置插入选项卡页:
不要忘记撤消更改:
或
变体 2
Variant 1
In order to avoid visual klikering you might need to use:
or
Remove a tab page:
Add a tab page:
Insert a tab page at specific location:
Do not forget to revers the changes:
or
Variant 2
迄今为止提供的解决方案过于复杂。
阅读最简单的解决方案:
http://www.codeproject.com/Questions/614157/How -to-Hide-TabControl-Headers
您可以使用此方法使它们在运行时不可见:
Solutions provided so far are way too complicated.
Read the easiest solution at:
http://www.codeproject.com/Questions/614157/How-to-Hide-TabControl-Headers
You could use this method to make them invisible at run time:
我将@Jack Griffin 的答案和@amazedsaint 的答案结合起来(dotnetspider 代码片段分别)到单个 TabControlHelper 中。
TabControlHelper 允许您:
使用示例:
I combined the answer from @Jack Griffin and the one from @amazedsaint (the dotnetspider code snippet respectively) into a single TabControlHelper.
The TabControlHelper lets you:
Example on how to use it:
您可以将标签页的父级设置为 null 以隐藏
并显示刚刚设置的 tabpage 父级到 tabcontrol
you can set the parent of the tabpage to null for hiding
and to show just set tabpage parent to the tabcontrol
创建一个新的空类并将其放入其中:
2- 在表单代码中添加对 ExtensionMethods 命名空间的引用:
3- 现在您可以使用
yourTabPage.IsVisible();
检查其可见性,yourTabPage.HidePage();
隐藏它,yourTabPage.ShowPageInTabControl(parentTabControl);
显示它。Create a new empty class and past this inside it:
2- Add reference to ExtensionMethods namespace in your form code:
3- Now you can use
yourTabPage.IsVisible();
to check its visibility,yourTabPage.HidePage();
to hide it, andyourTabPage.ShowPageInTabControl(parentTabControl);
to show it.像这样使用它:
选项卡的原始顺序保存在完全隐藏在匿名函数内的列表中。 保留对函数实例的引用,并保留原始 Tab 键顺序。
Use it like this:
The original ordering of the tabs is kept in a List that is completely hidden inside the anonymous function. Keep a reference to the function instance and you retain your original tab order.
好吧,如果您不想弄乱现有代码而只想隐藏选项卡,则可以修改编译器生成的代码以注释将选项卡添加到选项卡控件的行。
例如:
以下行将名为“readformatcardpage”的选项卡添加到名为“tabcontrol”的 Tabcontrol
this.tabcontrol.Controls.Add(this.readformatcardpage);
以下内容将阻止将选项卡添加到选项卡控件
//this.tabcontrol.Controls.Add(this.readformatcardpage);
Well, if you don't want to mess up existing code and just want to hide a tab, you could modify the compiler generated code to comment the line which adds the tab to the tabcontrol.
For example:
The following line adds a tab named "readformatcardpage" to a Tabcontrol named "tabcontrol"
this.tabcontrol.Controls.Add(this.readformatcardpage);
The following will prevent addition of the tab to the tabcontrol
//this.tabcontrol.Controls.Add(this.readformatcardpage);
微软+1 :-) 。
我设法这样做:
(它假设您有一个显示下一个 TabPage 的
Next
按钮 -tabSteps
是选项卡控件的名称)启动时,将所有选项卡保存在适当的列表中。
当用户按下
Next
按钮时,删除选项卡控件中的所有 TabPage,然后使用正确的索引添加它:更新
+1 for microsoft :-) .
I managed to do it this way:
(it assumes you have a
Next
button that displays the next TabPage -tabSteps
is the name of the Tab control)At start up, save all the tabpages in a proper list.
When user presses
Next
button, remove all the TabPages in the tab control, then add that with the proper index:Update
作为一种廉价的解决方法,我使用标签来掩盖我想要隐藏的选项卡。
然后我们可以使用标签的visible属性作为替代。 如果有人确实走这条路,请不要忘记处理键盘敲击或可见性事件。 您不希望左右光标键暴露您要隐藏的选项卡。
As a cheap work around, I've used a label to cover up the tabs I wanted to hide.
We can then use the visible prop of the label as a substitute. If anyone does go this route, don't forget to handle keyboard strokes or visibility events. You wouldn't want the left right cursor keys exposing the tab you're trying to hide.
不确定“Winforms 2.0”,但这已经过尝试和证明:
http://www.mostthingsweb.com/2011/01/hiding-tab-headers-on-a-tabcontrol-in-c/
Not sure about "Winforms 2.0" but this is tried and proven:
http://www.mostthingsweb.com/2011/01/hiding-tab-headers-on-a-tabcontrol-in-c/
在 WPF 中,这非常简单:
假设您已经为 TabItem 指定了名称,例如,
您可以在表单后面的代码中包含以下内容:
应该注意的是,名为
的
已创建,其User
对象userAccessLevel
属性设置为AccessLevelEnum
用户定义的枚举值之一...无论如何; 这只是我决定是否显示选项卡的一个条件。In WPF, it's pretty easy:
Assuming you've given the TabItem a name, e.g.,
You could have the following in the code behind the form:
It should be noted that a
User
object nameduser
has been created with it'sAccessLevel
property set to one of the user-defined enum values ofAccessLevelEnum
... whatever; it's just a condition by which I decide to show the tab or not.我也有这个疑问。 tabPage.Visible 没有像前面所说的那样实现,这是一个很大的帮助(+1)。 我发现你可以覆盖该控件,这会起作用。 有点死了,但我想在这里为其他人发布我的解决方案......
I also had this question. tabPage.Visible is not implemented as stated earlier, which was a great help (+1). I found you can override the control and this will work. A bit of necroposting, but I thought to post my solution here for others...
我使用了相同的方法,但问题是,当从选项卡控件 TabPages 列表中删除选项卡页时,它也会从选项卡页控件列表中删除。 并且当表单被释放时它并没有被释放。
因此,如果您有很多此类“隐藏”标签页,您可以 获取 Windows 句柄超出配额错误,只有应用程序重新启动才能修复它。
I've used the same approach but the problem is that when tab page was removed from the tab control TabPages list, it is removed from the tab page Controls list also. And it is not disposed when form is disposed.
So if you have a lot of such "hidden" tab pages, you can get windows handle quota exceeded error and only application restart will fix it.
如果您正在谈论 AjaxTabControlExtender,请设置每个选项卡的 TabIndex 并根据您的需要设置 Visible 属性 True/False。
myTab.Tabs[1].Visible=true/false;
If you are talking about AjaxTabControlExtender then set TabIndex of every tabs and set Visible property True/False according to your need.
myTab.Tabs[1].Visible=true/false;
复制粘贴试试吧,上面的代码已经在vs2010中测试过了,可以运行。
Just copy paste and try it,the above code has been tested in vs2010, it works.
隐藏 TabPage 并删除标题:
显示 TabPage 并可见标题:
Hide TabPage and Remove the Header:
Show TabPage and Visible the Header: