WebBrowser Control

Browser Commands

Now then The Nitty-Gritty. Opening, Saving and Printing in the web browser. In the menu editor create 3 new options called mnuopen, mnusave and mnuprint. Give them a caption related to their functions, i.e. open, save and print. Now then here is when it gets a bit silly. You now use more functions of Internet Explorer to do these things, as the Common Dialog function doesn’t work at all

Select the options and type in the following in each sub (which I have also labelled so now confusion could happen)

Private Sub mnuOpen_Click()
    '// tell the web browser control to prompt the user
    '// for a file to open
    On Error Resume Next
    WebBrowser1.ExecWB OLECMDID_OPEN, OLECMDEXECOPT_PROMPTUSER
End Sub

Private Sub mnuPrint_Click()
    '// tell the web browser control to print the current page
    On Error Resume Next
    WebBrowser1.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER
End Sub

Private Sub mnuSave_Click()
    '// tell the web browser to save the page
    On Error Resume Next
    WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_PROMPTUSER
End Sub

Now then if all went well then you see this thing:

And all the controls work as well can be!!

You will notice that both the Save, Open and Print commands all used the ExecWB method of the WebBrowser. This function also as some extra functionality, not covered yet. In the table below, I have listed all the other constants you can pass (that I can get to work)... have a try!

Constant Name Value Action...
OLECMDID_SAVEAS 4 Displays the save as dialog
OLECMDID_PRINT 6 Displays print dialog
OLECMDID_PAGESETUP 8 Displays page setup dialog
OLECMDID_PROPERTIES 10 Displays page properties dialog
OLECMDID_SELECTALL 17 Selects all the text in the active frame or page
OLECMDID_REFRESH 22 Reloads the page
OLECMDID_COPY 12 Copies the selected text
OLECMDID_STOPDOWNLOAD 30 Stops the current download

You can also see that at the moment, our web browser doesn't look very 'pretty'. To improve this, you could use the Toolbar control, and generally enhance the user interface. Why not have a go?

You can download the source code here, or if you have perhaps have other queries then you can email me at paul@thtproductions.co.uk with web browser tutorial in the subject line. Well then that’s all folks!!!

Paul Hughes

Http:\www.thtproductions.co.uk

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are 10 types of people in the world, those who can read binary, and those who can't.”