Last Modified: Thu, 12 Jun 2008 17:13:00 +0000 ; Created: Thu, 12 Jun 2008 17:13:00 +0000
|So I discovered today how to use a WebBrowser object on a Form in Visual Basic 2008 that would zoom the page just like you can in IE7.
The first method I tried used the .NET Framework Components, System.Windows.Forms, WebBrowser control object. This is a simplified interface for showing an IE web browser on your form.
After the document has loaded (see WebBrowser DocumentComplete method) you can call Me.WebBrowser1.Document.Body.Style = "zoom 10%" to change the zoom. However you will see a brief flicker as the document will already be displayed and visible at the normal zoom before going to your new zoom.
One option would be to hide the web browser control until after the document is loaded, and you've changed the zoom. However that might result in unwanted screen flicker as well.
The disadvantage of this method is that you must reset the zoom each time you navigate to a different URL with the control.
Second Method (Best)
I searched on the Internet and also saw references to a ExecWB method. Unfortantely this method doesn't exist for the .Net Framework Component "WebBrowser." I did find another component which I was able to use that had this method.
COM Components, Microsoft Web Browser, ieframe.dll
Adding this to my toolbox and then to my form gave me a AxWebBrowser1 object. Maybe not as friendly or simple as the WebBrowser .Net one, but it has the ExecWB method I needed to set the zoom!
I start by having my Form1_Load method call:
This allows the control to load a quick document as required before making the zoom call.
Below is the method I used to set the zoom one time before the control was rendered: