WebBrowser Control

More Navigation

You will have noticed that in explorer, there are far more buttons than just Back and Forward, so lets add them now. Alongside the first 2 buttons (forward and back) place four new command buttons called cmdstop, cmdhome, cmdsearch and cmdrefresh. In the caption properties, call them stop, home, search and refresh (or something else if you want). Double click on each of them and add the following code for each button….

HOME

WebBrowser1.Navigate "http:\www.thtproductions.co.uk"

STOP

WebBrowser1.Stop

SEARCH

Webbrowser1.gosearch

REFRESH

Webbroswer1.stop

Now then You by now have noticed that if you resize the for the web browser window doesn’t resize with it. To get this to work, all you need to do is type in the code below into the Resize event of the Form, and the window will resize automatically with the window.

WebBrowser1.Move 0, 0, ScaleWidth, ScaleHeight

You can also simply set the Width and Height properties instead, if you wish.

However, now you will notice the problem below:


It would seem only way to get around this is to pull the webbrowser window to the top of the form as high as it will allow (i.e. the top of the browser window meets the part of the form with the little icon and the name of the form in the little bar.) But then when you run the program again you will find that the buttons are over the web browser window. Bummer. Never fear Paul is here. In order to get things right again all you need to do is to take into account the space taken up by the buttons and combo box when the form is resized. To do this, all you need to do is change the code in the Resize event to 

'resize the webbrowser control to fill the window (ScaleWidth and ScaleHeight)
'840 is the space taken up by the buttons!
WebBrowser1.Move 0, 840, ScaleWidth, ScaleHeight - 840

Simple!

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.

“Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.”