VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Dynamically Add WebBrowser Control at runtime without a Reference

by Dave Slinn (2 Submissions)
Category: Internet/HTML
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (8 Votes)

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.

Rate Dynamically Add WebBrowser Control at runtime without a Reference

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


Download this snippet    Add to My Saved Code

Dynamically Add WebBrowser Control at runtime without a Reference Comments

No comments have been posted about Dynamically Add WebBrowser Control at runtime without a Reference. Why not be the first to post a comment about Dynamically Add WebBrowser Control at runtime without a Reference.

Post your comment

Subject:
Message:
0/1000 characters