Search Tools Links Login

Dynamically Add WebBrowser Control at runtime without a Reference


Visual Basic 6, or VB Classic

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

Code

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


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 "http://www.planet-source-code.com"



?á?á?á Exit Sub

ErrHandler:

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

End Sub



About this post

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

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.