Click here to Skip to main content
6,629,377 members and growing! (19,014 online)
Email Password   helpLost your password?
Languages » VB.NET » HowTo     Intermediate License: The Code Project Open License (CPOL)

Using ExecWB with the native .NET 2.0 WebBrowser control

By Rocco Labellarte

How to zoom the standard WebBrowser control by accessing ExecWB.
VB (VB 8.0, VB 9.0), COM, WinForms, Dev
Posted:17 Jun 2008
Views:17,361
Bookmarked:17 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
5 votes for this article.
Popularity: 3.26 Rating: 4.67 out of 5

1

2

3
2 votes, 40.0%
4
3 votes, 60.0%
5

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:
Class Form1

End Class

with the following code:

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)

About the Author

Rocco Labellarte


Member
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.
Occupation: Chief Technology Officer
Company: Vobis Consulting Ltd
Location: United Kingdom United Kingdom

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 10 of 10 (Total in Forum: 10) (Refresh)FirstPrevNext
GeneralProblems with Web Brower Control in Vista PinmemberFalcon12319:49 29 Jul '09  
General'%' of zoom PinmemberIPS Company10:50 13 Sep '08  
GeneralRe: '%' of zoom PinmemberJared James Sullivan16:07 20 Jan '09  
GeneralError: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) PinmemberTerriTop10:04 17 Jun '08  
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) PinmemberRocLab11:57 17 Jun '08  
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) PinmemberTerriTop15:56 17 Jun '08  
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) PinmemberRocLab12:00 17 Jun '08  
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) PinmemberRocLab12:05 17 Jun '08  
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) PinmemberMEIRB11113:54 20 May '09  
GeneralRe: Error: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DRAGDROP_E_NOTREGISTERED)) PinmemberxZaria22:49 24 Jul '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 17 Jun 2008
Editor: Smitha Vijayan
Copyright 2008 by Rocco Labellarte
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project