以编程方式隐藏/删除 VB.NET 中的标签页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12740073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Programmatically hide/remove tabpages in VB.NET
提问by mrn
I have 10 tabpages on my form. Based on an input in a textbox, I want to programmatically remove number of tab pages, i.e. if textbox input is 3 then only first 3 tabpages should be visible and tabpages 4 to 10 must be removed or should not be visible. I tried following without any success,
我的表单上有 10 个标签页。基于文本框中的输入,我想以编程方式删除标签页的数量,即如果文本框输入为 3,则只有前 3 个标签页应该可见,而标签页 4 到 10 必须删除或不可见。我尝试跟随但没有成功,
For i = 0 To 9
Form1.TabControl1.TabPages.Remove(Form4.TabControl1.TabPages((val(textbox1.text)) + i))
Next
(No exceptions or errors are generated for above statements)
(以上语句不会产生异常或错误)
What is wrong with these statements?
这些陈述有什么问题?
采纳答案by MMALSELEK
check this.
检查这个。
For i As Integer = TextBox1.Text + 1 To 9
Form1.TabControl1.TabPages.Remove(Form4.TabControl1.TabPages(TextBox1.Text + 1))
Next
or
或者
For index As Integer = 9 To TextBox1.Text + 1 Step -1
Me.TabControl1.TabPages.Remove(Me.TabControl1.TabPages(index))
Next
回答by Christian Sauer
Never use your Input unfiltered. Put the Textbix1.Text Input in a integer.tryparse construct. Also, activate Option strict for better code quality.
切勿使用未经过滤的输入。将 Textbix1.Text Input 放入 integer.tryparse 构造中。此外,激活 Option strict 以获得更好的代码质量。
For your Problem:
对于您的问题:
Dim MaxVisible as Integer
Dim Sucess as Boolean
Sucess=Integer.Tryparse(textbox1.text, MaxVisible)
If Sucess=True
For index As Integer = 9 To MaxVisible + 1 Step -1
Me.TabControl1.TabPages(Index).visible=false
End If
That should make the unwanted tabcontrols invisible. I dont know if Tabpages(index) works, maybe you must youse getitems instead - I have no Winforms Project at hand to test it. More Information on TabControl: http://msdn.microsoft.com/de-de/library/system.windows.forms.tabcontrol.aspx
这应该使不需要的 tabcontrols 不可见。我不知道 Tabpages(index) 是否有效,也许您必须改为使用 getitems - 我手头没有 Winforms 项目来测试它。有关 TabControl 的更多信息:http: //msdn.microsoft.com/de-de/library/system.windows.forms.tabcontrol.aspx