Using System.Windows.Forms.WebBrowser.ActiveXInstance

0.00 avg. rating (0% score) - 0 votes

Expanding the WebBrowser control functionalities by using its ActiveXInstance property.

The WebBrowser control has a property called ActiveXInstance which is its run-time ActiveX instance and exposes many other methods/properties not available in the main control.

However, since ActiveXInstance is Object and requires late-binding to access all its methods and properties, Option Strict needs to be turned off in order to use it.

To use the WebBrowser extra functionalities: call WebBrowser.ActiveXInstance.ExecBB()

Define enums for use with ExecBB:

Private Enum Exec
OLECMDID_OPTICAL_ZOOM = 63
OLECMDID_SELECTALL = 17
OLECMDID_COPY = 12
OLECMDID_CLEARSELECTION = 18
End Enum

Private Enum ExecOpt
OLECMDEXECOPT_DODEFAULT = 0
OLECMDEXECOPT_PROMPTUSER = 1
OLECMDEXECOPT_DONTPROMPTUSER = 2
OLECMDEXECOPT_SHOWHELP = 3
End Enum

Copy selected text to clipboard:

Me.WebSMSView.ActiveXInstance.ExecWB(Exec.OLECMDID_COPY, ExecOpt.OLECMDEXECOPT_DODEFAULT)

Select all text:

Me.WebSMSView.ActiveXInstance.ExecWB(Exec.OLECMDID_SELECTALL, ExecOpt.OLECMDEXECOPT_DODEFAULT)

Zoom to 75%:

Me.WebSMSView.ActiveXInstance.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, ExecOpt.OLECMDEXECOPT_DODEFAULT, 75, 0)

To use a custom context menu in the WebBrowser control, the default context menu needs to be disabled by setting WebBrowser.IsWebBrowserContextMenuEnabled to false.

Reference:


  • Copy the contents of the WebBrowser control to the Clipboard
  • Using ExecWB with the native .NET 2.0 WebBrowser control
  • Allow only Copy/Paste Context Menu in System.Windows.Forms.WebBrowser Control
  • ExecWB Method
  • 0.00 avg. rating (0% score) - 0 votes
    ToughDev

    ToughDev

    A tough developer who likes to work on just about anything, from software development to electronics, and share his knowledge with the rest of the world.

    4 thoughts on “Using System.Windows.Forms.WebBrowser.ActiveXInstance

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>