![]() |
Languages »
VB.NET »
HowTo
Intermediate
License: The Code Project Open License (CPOL)
Using ExecWB with the native .NET 2.0 WebBrowser controlBy Rocco LabellarteHow to zoom the standard WebBrowser control by accessing ExecWB. |
VB (VB 8.0, VB 9.0), COM, WinForms, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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.
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).
WebBrowser control, dragging it from the toolbox onto the formWebBrowser's URL property in the propertygrid to something like this: http://www.codeproject.comButton control from the toolbox onto the formButton from Button1 to ZoomClass 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
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.
This is the first release of this solution. If anyone has suggestions on how to make it shorter, let me know.
General
News
Question
Answer
Joke
Rant
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 |