Question about tabcontrols

I have a tab control (tabControl1). When I click on an entry in my menustrip (menu1) it creates a new tabpage in my tabcontrol (tabControl1).

What I want to know is how I can make it so if the tab has already been created, then instead of creating another one it will instead focus the tab that is already open.

Thank you.




Answer this question

Question about tabcontrols

  • anderson.fvgn

    Dim Found As Boolean = False
    For Each Page As TabPage In TabControl1.TabPages
    If Page.Text = "New_Page_Text" Then
    TabControl1.SelectTab(Page.Name)
    Found = True
    Exit For
    End If
    Next
    If Not Found Then
    ' Add new page here
    End If


  • Bob Bojanic

    I didn't like your suggestion so I use it's basic code and created the following instead.

    Try
    TabControl1.SelectTab(loz)
    Catch ex As Exception
    TabControl1.TabPages.Add(loz)
    End Try

    where loz is the name of the tabpage to be added.

    What this does is select the tab. If it doesn't exist then the exception is thrown and the tab is created.
    Thanks for your suggestion. It helped me alot.



  • Question about tabcontrols