I had a need to manipulate the activities of a webpage hosted by the
WebBrowser control from within a Visual Basic project. The requirement was
that VB must be able to communicate with VBScript, and vice versa. This is
how I accomplished the task.
I created a new Visual Basic project and placed the WebBrowser control on
its default form. I initially set that control properties with a name of
WebBrowser1, and as not visible. I placed a command button on top of the
WebBrowser1 control, right-clicked it and sent it to the front and then
right-clicked the WebBrowser1 control and sent it to the back. I set the
form properties to not display a menu bar.
I set the click event handler for the command button to end the program. In
the form unload event is where I destroyed all objects before the VB program
This code would set the form to entirely fill a 1024x768 screen:
Me.Move 0, 0
Me.Width = 15360: Me.Height = 11520
Me.Visible = True
This code would then initialize that control for full screen and no taskbar
WebBrowser1.Left = 10: WebBrowser1.Top = 10
WebBrowser1.Height = Me.Height - 20: WebBrowser1.Width = Me.Width - 20
WebBrowser1.AddressBar = False
WebBrowser1.MenuBar = False
WebBrowser1.StatusBar = False
WebBrowser1.FullScreen = True
WebBrowser1.TheaterMode = True
WebBrowser1.Visible = True
I defined a global variable named PageReady. Then this code in
PageReady = True
Then I created Sub MyTest() and placed this code into it:
WebBrowser1.Navigate MyPath & "Page1.html" 'MyPath is previously defined
PageReady = False
While PageReady = False: DoEvents: DoEvents: DoEvents: Wend 'Page loaded
'Set the text value in the page control named txtWebBrowser!
WebBrowser1.Document.All.Item("txtWebBrowser").Value = "Message from VB6
'Get the text value in the page control named txtWebBrowser!
That completes the VB part. I then created a webpage called Page1.html,
existing in the MyPath that was specified in the above VB code. The page had
<BODY BGCOLOR="#000000" TEXT="#FFFFFF" LINK="#00FFFF"
VLINK="#FF0000" ALINK="#FF00FF" SCROLL="NO"
<FONT SIZE=4 FACE="ARIAL">
<CENTER><H1>Theme 1 Page</H1></CENTER>
<TEXTAREA NAME="txtWebBrowser"ROWS=1 COLS=50
Launching the webpage by itself will cause the textbox text, initially set
to "Default Text", to be changed to "READY" after the page has loaded.
Launching the page via running the VB project will cause the webpage textbox
text to be changed to "Message from VB6 Code!". I commented out the VB code
that will obtain that textbox content.
This methodology lets code in the webpage communicate back and forth with VB
code via the webpage textbox. This allows synchronizing of code in both of
the applications. I've shown the basic way of providing cross communications
between the applications, but I'll leave it up to others to do something
with it! Maybe someone else will write a complete tutorial and project for
others, rather than just a general explanation as I've done here.