0

so as you can see from the title, I want to be able to double click on the tab (top of the tab where it has the name of it) and I want it to remove. I have currently got the following code to create the tab:

Private Sub Panel1_DoubleClick(sender As Object, e As EventArgs) Handles Panel1.DoubleClick
    Dim tab As New TabPage
    Dim newtab As New tab
    newtab.Show()
    newtab.Dock = DockStyle.Fill
    newtab.TopLevel = False
    tab.Controls.Add(newtab)
    Form1.TabControl1.TabPages.Add(tab)
    Form1.TabControl1.SelectedTab = tab


End Sub

So the tabs are created by double clicking on the panel. This works fine, but I now want to be able to Double Click a tab and it gets rid of it. I tried using AddHandler but I couldn't quite get it. Thanks for the help :)

James
  • 1
  • Possible duplicate of [Programatically hide/remove tabpages in VB.NET](http://stackoverflow.com/questions/12740073/programatically-hide-remove-tabpages-in-vb-net) – David Wilson Mar 11 '16 at 15:05

1 Answers1

0

This should work for the DoubleClick on the tab header. Hope this helps:

Private Sub TabPage_DoubleClick(sender As Object, e As MouseEventArgs) Handles TabControl1.DoubleClick
    Dim myTabControl As TabControl = DirectCast(sender, TabControl)
    If myTabControl Is Nothing Then Return

    For Each myTabPage As TabPage In myTabControl.TabPages
        If myTabControl.GetTabRect(myTabPage.TabIndex).Contains(e.Location) Then
            myTabControl.TabPages.Remove(myTabPage)
            Return
        End If
    Next
End Sub
ms_dos
  • 92
  • 10