Click here to Skip to main content
15,868,016 members
Articles / Desktop Programming / Windows Forms
Article

Using ExecWB with the native .NET 2.0 WebBrowser control

Rate me:
Please Sign up or sign in to vote.
4.67/5 (5 votes)
17 Jun 2008CPOL1 min read 124.3K   29   16
How to zoom the standard WebBrowser control by accessing ExecWB.

Introduction

One of the most annoyingly interesting components within the VB.NET 2008 environment is the WebBrowser control (or class, if you prefer) that is bundled as standard. It exposes a number of common methods and properties, but lacks one of the most useful elements that can be found in the full-blown web browser (a.k.a. SHDocVw or Ieframe.dll) version, namely the ExecWB command. The following class provides a simple example of how to harness the power of ExecWB from the System.Windows.Forms.WebBrowser class.

Background

This solution came about as I researched using the WebBrowser control and stumbled into the complex world of variations on a theme. Why all of this power couldn't be harnessed in a single solution is beyond me. However, my mission is to continue simplifying a unified theory of everything (relating to the Microsoft WebBrowser).

Using the code

  1. Create a new project in VB.NET 2008
  2. Display your form in design mode
  3. Add a standard WebBrowser control, dragging it from the toolbox onto the form
  4. Change the WebBrowser's URL property in the propertygrid to something like this: http://www.codeproject.com
  5. Add a Button control from the toolbox onto the form
  6. Change the Text property of the Button from Button1 to Zoom
  7. Switch to the source code edit mode
  8. Replace the code, which should look like this:
VB
Class Form1

End Class

with the following code:

VB
Public Class Form1
Private Enum Exec
  OLECMDID_OPTICAL_ZOOM = 63
End Enum
Private Enum ExecOpt
  OLECMDEXECOPT_DODEFAULT = 0
  OLECMDEXECOPT_PROMPTUSER = 1
  OLECMDEXECOPT_DONTPROMPTUSER = 2
  OLECMDEXECOPT_SHOWHELP = 3
End Enum
Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
  Try
    Dim Res As Object = Nothing
    Dim MyWeb As Object
    MyWeb = Me.WebBrowser1.ActiveXInstance
    MyWeb.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, _
          ExecOpt.OLECMDEXECOPT_DONTPROMPTUSER, 50, IntPtr.Zero)
  Catch ex As Exception
    MsgBox("Error:" & ex.Message)
  End Try
 End Sub
End Class

Points of interest

The code above only shows the enumeration for zooming a web page. To make use of all of the OLECMDID enumeration commands, simply add them to the Enum Exec shown above. You can find all the available enumerations at MSDN.

History

This is the first release of this solution. If anyone has suggestions on how to make it shorter, let me know.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Vobis Consulting Ltd
United Kingdom United Kingdom
I've been around since the beginning of time (well, nearly fifty years anyway), and I've enjoyed programming since the days of DOS 1.0 with assembly language, MS-BASIC, GW-BASIC, QuickBASIC, Visual BASIC and now VB.NET.

Comments and Discussions

 
QuestionZoom with Visual Basic. Pin
Mark AJA2-Oct-11 6:52
Mark AJA2-Oct-11 6:52 
GeneralSelected Tag(s) In WB Pin
taqech20-May-10 5:38
taqech20-May-10 5:38 
GeneralProblems with Web Brower Control in Vista Pin
Falcon12329-Jul-09 18:49
Falcon12329-Jul-09 18:49 
General'%' of zoom Pin
IPS Company13-Sep-08 9:50
IPS Company13-Sep-08 9:50 
GeneralRe: '%' of zoom Pin
J Sullivan20-Jan-09 15:07
J Sullivan20-Jan-09 15:07 
GeneralError: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) Pin
TerriTop17-Jun-08 9:04
TerriTop17-Jun-08 9:04 
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) Pin
Rocco Labellarte17-Jun-08 10:57
Rocco Labellarte17-Jun-08 10:57 
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) Pin
TerriTop17-Jun-08 14:56
TerriTop17-Jun-08 14:56 
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) Pin
Rocco Labellarte17-Jun-08 11:00
Rocco Labellarte17-Jun-08 11:00 
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) Pin
Rocco Labellarte17-Jun-08 11:05
Rocco Labellarte17-Jun-08 11:05 
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) Pin
MEIRB11120-May-09 12:54
MEIRB11120-May-09 12:54 
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) Pin
xZaria24-Jul-09 21:49
xZaria24-Jul-09 21:49 
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) Pin
Minooch4-Aug-10 15:45
Minooch4-Aug-10 15:45 
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) Pin
vinay5718-Jun-11 22:03
vinay5718-Jun-11 22:03 
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) Pin
fredclown23-Sep-11 9:06
fredclown23-Sep-11 9:06 
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) Pin
Rakesh_Sharma235-Dec-11 23:17
Rakesh_Sharma235-Dec-11 23:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.