
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:
yourBrowser.AddTab("http://www.google.com")
yourBrowser.GoBack()
yourBrowser.CloseOtherTabs()
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
Private Sub myBrowser_TabAmountChanged() Handles myBrowser.TabAmountChanged
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 :)