Results 1 to 40 of 101

Thread: Tabbed WebBrowser - a work in progress

Threaded View

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Tabbed WebBrowser - a work in progress

    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:
    1. Public Class WebBrowserTabPage
    2.     Inherits System.Windows.Forms.TabPage
    3.  
    4.     Private _browser As New WebBrowser
    5.  
    6.     Public ReadOnly Property Browser() As WebBrowser
    7.         Get
    8.             Return Me._browser
    9.         End Get
    10.     End Property
    11.  
    12.     Public Sub New()
    13.         Me._browser.Dock = DockStyle.Fill
    14.         Me.Controls.Add(Me._browser)
    15.     End Sub
    16.  
    17. 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:
    1. Public Sub Navigate(ByVal urlString As String)
    2.     Me._browser.Navigate(urlString)
    3. 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.
    Attached Files Attached Files
    Last edited by jmcilhinney; May 21st, 2008 at 09:09 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width