Lots of people have asked lots of questions relating to building a tabbed Web browser. I've seen the same questions asked again and again so, rather than answering them again and again, I'm going to build a tabbed Web browser, piece by piece, and post the result here.
The first stage is the WebBrowser controls on the TabPages. It's usually beginners but I've answered the question of how to put multiple WebBrowser controls on multiple TabPages too many times already. One of the basic ideas of OOP is encapsulation. Another is inheritance. Let's put those together to inherit the TabPage control to encapsulate a WebBrowser control.
VB.NET Code:
Public Class WebBrowserTabPage
Inherits System.Windows.Forms.TabPage
Private _browser As New WebBrowser
Public ReadOnly Property Browser() As WebBrowser
Get
Return Me._browser
End Get
End Property
Public Sub New()
Me._browser.Dock = DockStyle.Fill
Me.Controls.Add(Me._browser)
End Sub
End Class
Now, instead of adding regular TabPages to your TabControl you create WebBrowserTabPage objects and add them. Each one IS a TabPage so it can be added to a TabControl, and each one creates and displays it's own WebBrowser control.
I've added a ReadOnly property via which you can access the WebBrowser control from the TabPage. This allows you to access properties, methods and events of the WebBrowser from outside the TabPage. If you wanted to be "more correct" you could keep the WebBrowser private and declare pass-through members in the WebBrowserTabPage class, e.g.
VB.NET Code:
Public Sub Navigate(ByVal urlString As String)
Me._browser.Navigate(urlString)
End Sub
That would be considerably more work though, as the WebBrowser class has quite a few members.
Stay tuned for additions and improvements but, for now, it's a start.
Last edited by jmcilhinney; May 21st, 2008 at 09:09 AM.