Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

VB.Net multitab browser

0.00/5 (No votes)
23 Feb 2009 1  
A vb.net browser control with multitab functionallity and lot's of build in features

browserDemo.gif

Introduction    

After building multiple small web browsers from scratch, and getting a lot of questions about the same functionality over and over again, I decided to create a robust browser control with the most common functionality build in. It is now very easy to implement, and has the following functionality build in:

  • Multi tab browser using a powerful custom made tab user control
  • New window support. New windows will open in your application, and not the default browser 
  • Integrated zoom function
  • Fully automated URL auto correction
  • Tab titles with optional truncating
  • Integrated status bar with automated status  

Using this control can spare you hours of developing time and is very easy to integrate. It contains all the needed methods, properties and events to easily link it to other parts of your interface.

Exploring the control   

The browser control contains a tab control with on each tab a seperate native .net web browser component. For more info about the tab control, please visit this topic. Methods like .GoForeward() or .Navigate("url") will automatically be applied to the selected tab.

Another feature I often see questions about on programming forums is the opening of new windows (so <a href traget="_blank">link</a>) inside the program itself, and not the default web browser of the host machine. This is done using the SHDoCVw assembly, which provides a new window event for it's version of the web browser component that also passes the url of the new page. The browser control handles this event by adding a new tab with the corect url, and then canceling it.

 Some other small features are present, like an integrated zoom function, auto correction of urls (google will be changed into www.google.com) and the browser status in the statusbar.

Using the code  

Using the control is pretty simple. Just declare a new instance of it, add it to your form control collection and your basically done. When you want to create an interface around the control for navigation, the required methods are pretty simple. Here you have a few examples:

' Adding a new tab
yourBrowser.AddTab("http://www.google.com")
' Go back in the history. The control will automatically apply this to the selected tab
yourBrowser.GoBack()		 
' Close all other tabs
yourBrowser.CloseOtherTabs()	
' Example of how to navigate the current tab 
    Private Sub tsCbxUrl_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tsCbxUrl.KeyDown
        If e.KeyCode = Windows.Forms.Keys.Return Then Me.myBrowser.Navigate(tsCbxUrl.Text)
    End Sub 
 ' Changing your interface after a browser event
    Private Sub myBrowser_TabAmountChanged() Handles myBrowser.TabAmountChanged
        ' Enable or disable the close buttons (in the menu) depending on if tabs can be closed
        tmiCloseTab.Enabled = myBrowser.CanCloseTab
        tmiCloseOthers.Enabled = myBrowser.CanCloseTab
    End Sub
For more examples of how to use the methods and events, check out the source project and demo. The source code and demo project contains the small application you can see on the screen shot on top of this page and the required dependencies of the component.

Updates 

This control can still be improved a lot regarding performance, usability and convention. I will try to release a new version soon, but contributions, critics and suggestions are very welcome :)


License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here