fireBand
fireBand

Reputation: 957

Select a particular tabpage if already open in VB.NET

I have created a tab control and few forms. Each form opens in a separate tab when a button is clicked

I have take care so that the form does not open again in a new tab if its already open. But I am having trouble bringing the tab to focus.

I want to Select the From in the tab and bring it to focus if its already in the tab list.

Here is my Code

 //Function to open form in new tab
Private Sub openFormInTab(ByVal sender As Form, ByVal tp As TabPage)
    sender.TopLevel = False ' REQUIRED
    sender.FormBorderStyle = Windows.Forms.FormBorderStyle.None ' optional
    sender.Dock = DockStyle.Fill ' optional
    tp.Name = sender.Name
    tp.Controls.Add(sender)
    sender.Show()
    ProjectTabControl.TabPages.Add(tp)
    Me.ProjectTabControl.SelectedTab = tp
  End Sub

//Function to determine if the form is already open.

Public Function FormOpen(ByRef frmName As String) As Boolean
    For Each page As TabPage In ProjectTabControl.TabPages
      If page.Name = frmName Then
        Return True
      End If
    Next page
    Return False
  End Function

//I need function to bring the form to focus if its already open.

Thanks in advance.

Upvotes: 1

Views: 7670

Answers (1)

smelch
smelch

Reputation: 2543

In the FormOpen function before you return true use this line:

Me.ProjectTabControl.SelectedTab = page

Is this not what you did in the first function to get the new tab page in focus?

Upvotes: 2

Related Questions