Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add close button to my webbrowser tabs ?

Status
Not open for further replies.

DaviiD2010

Programmer
Apr 25, 2010
12
NL
Hi all . I got a tab in my webbrowser and a listbox. Every time i click a listbox item a html loads in to my new tab inside webbrowser controle. Now i want to add a close button to each tabs. so when i press that button i want that tab closes. I placed the code for adding new tabs when listbox item is getting clicked. Looking forward for some help.Thanks


Code:
Private Sub List1_Click()
 '
    ' populate SSTab1, WB1(nnTABs)
    '
  
        With List2
        If Option1.Value = True Then
        v1 = List1.ListIndex
        Else
        v1 = List1.ListIndex
        End If
        v2 = .List(v1)
        nnTABS = nnTABS + 1
        ' Tab
        With SSTab1
            .Tabs = nnTABS
            .Tab = nnTABS - 1
            If Option1.Value = True Then
           .Caption = Left(v2, InStr(v2, ".") - 1)
            Else
             .Caption = List1.List(List1.ListIndex) & ":" & List1.ListIndex
            End If
        End With
        
    
        ' WB1
        If nnTABS > 1 Then
            Load WB1(nnTABS - 1)
        End If
        With WB1(nnTABS - 1)
            .Container = SSTab1
            .Top = 1500
            .Left = 100
            .Height = 4300
            .Width = 5500
            .Visible = True
            .StatusBar = True
            .MenuBar = True
            If Option1.Value = True Then
            'MsgBox "wow"
            .Navigate2 App.Path & "/" & "singers/" & v2
            Else
            .Navigate2 App.Path & "/" & v2
            End If
        End With
      
  
    End With

End Sub
 
I don't think you can remove tabs from a SSTab control in the way you want to. As you've discovered, the way to add extra tabs is by changing the .Tabs value, and the way to remove tabs is using the same technique. However, you might want to remove the first tab and leave the others - which you can't do.

Try instead using the TabStrip control by ticking "Microsoft Winows Common Controls 6.0" in your toolbox. The TabStrip is NOT a container like SSTab but it will allow you to remove specific tabs.

All you really need for your application is one WebBrowser control and just change the URL when the user clicks a different tab on the TabStrip. You could store the URL in the .Tag property - there's one .Tag value per tab. Eg;
Code:
Private Sub List1_Click()
  Set NewTab = TabStrip1.Tabs.Add(, , IIf(Option1.Value, Left(v2, InStr(v2, ".") - 1), List1.List(List1.ListIndex) & ":" & List1.ListIndex)
  NewTab.Tag = App.Path & "/" & IIf(Option1.Value, "singers/", "") & v2
  NewTab.Selected = True 
End Sub

Private Sub TabStrip1_Click()
  WebBrowser1.Navigate2 TabStrip1.SelectedItem.Tag
End Sub

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Thanks for your reply. I keep getting syntax error in this line:

Code:
Set NewTab = TabStrip1.Tabs.Add(, , IIf(Option1.Value, Left(v2, InStr(v2, ".") - 1), List1.List(List1.ListIndex) & ":" & List1.ListIndex)

Does it created new tab for each click on listbox ? How about ability to close the tabs ?
 
There's a missing bracket, sorry:
Code:
Set NewTab = TabStrip1.Tabs.Add(, , IIf(Option1.Value, Left(v2, InStr(v2, ".") - 1), List1.List(List1.ListIndex)) & ":" & List1.ListIndex)
To close the tabs you need to add a Close button somewhere on screen (clicking it would close the current tab).
Code:
Private Sub Button1_Click()
  TabStrip1.Tabs.Remove TabStrip1.SelectedItem.Index
End Sub

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Thanks for your reply . Now i get this error:
Code:
Compile error:
Varibale not defined
pointing at :

Code:
NewTab =
Code:
Set NewTab = TabStrip1.Tabs.Add(, , IIf(Option1.Value, Left(List2.List(List1.ListIndex), InStr(List2.List(List1.ListIndex), ".") - 1), List1.List(List1.ListIndex)) & ":" & List1.ListIndex)
  NewTab.Tag = App.Path & "/" & v2
  NewTab.Selected = True
 
Ignore my last post. I fixed it by adding:

Dim newtab As Object

But why the first(default) tab is getting ignored .Nothing get loaded on that at start?
 
That's because the first tab has no .Tag value set. You could always start off with a TabStrip with no tabs at all by doing TabStrip1.Remove 1 in the Form_Load event.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top