WebBrowserControl for the .NET

Introduction

This article presents animplementation of a web browser control for the .NET Framework 1.1.It's more of a reference for what it does than how it's done.

This is not the result of my work but a collection of all the help I got along the way.

Background

The need for this control came froma project I'm working in. It's a smart client Windows application thathost application in web browsers and interacts with the pages.

What does it do?

This control is, mainly, an interop to the following COM interfaces:

Interface Description Usage
IWebBrowser2 This interface enables applications to implement an instance of theWebBrowser control (Microsoft ActiveX control) or control an instanceof the InternetExplorer application (OLE Automation). Note that not allof the methods listed below are supported by the WebBrowser control. Main web browser operation.
DWebBrowserEvents2 This interface designates an event sink interface that anapplication must implement in order to receive event notifications froma WebBrowser control or from the Microsoft Internet Explorerapplication. Note that not all of the events listed below are supportedby the WebBrowser control. Handling web browser events.
IDocHostUIHandler This custom interface enables an application hosting the WebBrowserControl or automating Microsoft Internet Explorer to replace the menus,toolbars, and context menus used by MSHTML. Showing the context menu, translating keys and URLs.
IDocHostShowUI A host can supply mechanisms that will show message boxes and Help by implementing the IDocHostShowUI interface. Showing message boxes (alert and confirm) and help.
IOleCommandTarget The IOleCommandTarget interface enables objects and theircontainers to dispatch commands to each other. For example, an object'stoolbars may contain buttons for commands such as Print, Print Preview,Save, New, and Zoom. Handling script errors.

Using the code

The MSHTML primary interop assembly (instaled with the .NET Framework SDK Version 1.1 – usually %ProgramFiles%Microsoft.NETPrimary Interop Assemblies) is needed to interop with HTML stuff.

Other than that, just add the control to your form or user control.

Known Issues

Along the way, I lost the ability to use the designer.

Download Source

Thanks ToIgor Tandetnik, Joao Melo, Luis Abreu, Oleg Mihailik and many more.

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!