Programmatically hide/remove tabpages in VB.NET

后端 未结 3 1608
野的像风
野的像风 2021-01-19 23:48

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 s

相关标签:
3条回答
  • 2021-01-20 00:09

    Never use your Input unfiltered. Put the Textbix1.Text Input in a integer.tryparse construct. Also, activate Option strict for better code quality.

    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

    0 讨论(0)
  • 2021-01-20 00:32

    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
    
    0 讨论(0)
  • 2021-01-20 00:34

    Actually, there is another approach that works well to make up for the lack of a visibility property.

    On the tab page itself, set the parent property to Nothing to hide it. when you want to show the tab page, set the tabpage.parent to the tab control.

    0 讨论(0)
提交回复
热议问题