So start Visual Basic (I use 2008 Express) and create a new Windows Forms applications. Add the following objects
-A Webbrowser, named "wbMain"
-A Textbox, named "txtURL"
-Four buttons, named "btnGO", "btnZoom50", "btnZoom100", "btnZoom200"
Your form should now look something like this:
Probably more visually gratifying than mine, but ah well...
So now switch to the code view, and add these declarations. Make sure they are part of any events or subs, but make sure they are included in the class for your form.
Private Enum ExecOpt 'A few options for what we want to do, using ActiveX 'This option will just carry out the default action OLECMDEXECOPT_DODEFAULT = 0 'This option will prompt the user before carrying out an action OLECMDEXECOPT_PROMPTUSER = 1 'This option will not prompt the user before carring out an action OLECMDEXECOPT_DONTPROMPTUSER = 2 'This option will show help OLECMDEXECOPT_SHOWHELP = 3 End Enum Private Enum Exec 'This is the main ActiveX declaration for the webbrowser Zoom OLECMDID_OPTICAL_ZOOM = 63 End Enum
Now go back to the windows forms designer, and double click 'btnZoom50'. Put this code in the Button.Click event:
'If for any reason we encounter any errors, we just want to ignore them. On Error Resume Next 'Declare an ActiveX instance for the webbrowser Dim wbInstance As Object = wbMain.ActiveXInstance 'Execute the zoom. The third parameter, the nubmer is the one which tells the ActiveX instance how far to zoom in on the browser, in this case by 50%. wbInstance.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, ExecOpt.OLECMDEXECOPT_DONTPROMPTUSER, 50, DBNull.Value)
So what did we do?
First, we told the program to ignore any errors, then made an ActiveX instance for the webbrowser (this only works in IE, or as the case may be the IE webbrowser control) and then we told the ActiveX instance to execute a certain event on the webbrowser.
So now go to the 'btnZoom100' and double click it. Add this code to the Button.Click event:
On Error Resume Next Dim wbInstance As Object = wbMain.ActiveXInstance wbInstance.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, ExecOpt.OLECMDEXECOPT_DONTPROMPTUSER, 100, DBNull.Value)
So we just did the same thing, but changed the zoom factor to 100%.
So now go to the 'btnZoom200' and double click it. Add this code to the Button.Click event:
On Error Resume Next Dim wbInstance As Object = wbMain.ActiveXInstance wbInstance.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, ExecOpt.OLECMDEXECOPT_DONTPROMPTUSER, 200, DBNull.Value)
Same old, same old but with 200%. I hope you get the idea...
Hope you enjoyed my short tutorial on webbrowser zooming. More on webbrowsers coming soon, as I'm stuck on holiday in france (cos of disruptions from the ash cloud), and I'm very bored.