Search Tools Links Login

Dynamically Add WebBrowser Control at runtime without a Reference

Allows VB applications to determine at run-time if Internet Explorer (4.0 or later) is installed, and if so, creates a WebBrowser. If not, a trappable error allows program to continue.

Original Author: Dave Slinn


Add a menu item named 'mnuCreate' with a caption of "&Create

Place the following code into a standard VB 6.0 form.

Private m_WebControl As VBControlExtender

Private Sub Form_Resize()

On Error Resume Next

??? ' resize webbrowser to entire size of form

??? m_WebControl.Move 0, 0, ScaleWidth, ScaleHeight

End Sub

Private Sub mnuCreate_Click()

On Error GoTo ErrHandler

??? ' attempting to add WebBrowser here ('Shell.Explorer.2' is registered

??? ' with Windows if a recent (>= 4.0) version of Internet Explorer is installed

??? Set m_WebControl = Controls.Add("Shell.Explorer.2", "webctl", Me)

??? ' if we got to here, there was no problem creating the WebBrowser

??? ' so we should size it properly and ensure it's visible

??? m_WebControl.Move 0, 0, ScaleWidth, ScaleHeight

??? m_WebControl.Visible = True

??? ' use the Navigate method of the WebBrowser control to open a

??? ' web page

??? m_WebControl.object.navigate ""

??? Exit Sub


??? MsgBox "Could not create WebBrowser control", vbInformation

End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 286 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.