Click here to Skip to main content
Licence CPOL
First Posted 14 Oct 2006
Views 57,806
Downloads 858
Bookmarked 21 times

WebBrowserControl for the .NET Framework 1.1

By | 15 Apr 2010 | Article
An implementation of a web browser control for the .NET Framework 1.1.

Introduction

This article presents an implementation 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 from a project I'm working in. It's a Smart Client Windows application that hosts applications 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 the WebBrowser control (Microsoft ActiveX control) or control an instance of the InternetExplorer application (OLE Automation). Note that not all of the methods listed below are supported by the WebBrowser control. Main web browser operation.
DWebBrowserEvents2 This interface designates an event sink interface that an application must implement in order to receive event notifications from a WebBrowser control or from the Microsoft Internet Explorer application. Note that not all of the events listed below are supported by the WebBrowser control. Handling web browser events.
IDocHostUIHandler This custom interface enables an application hosting the WebBrowser control 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 their containers to dispatch commands to each other. For example, an object's toolbars 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 (installed with the .NET Framework SDK Version 1.1 - usually %ProgramFiles%\Microsoft.NET\Primary Interop Assemblies) is needed to interop with HTML stuff.

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

Known Issues

When bound to a PropertyGrid, the PropertyGrid throws an Exception. Which means that we still don't have designer support.

Thanks To

Barry M., Igor Tandetnik, João Melo, Luís Abreu, Oleg Mihailik, and many more.

Update - July 8, 2007

A few bugs fixed and a change to the API.

License

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

About the Author

Paulo Morgado

Software Developer (Senior)
Paulo Morgado
Portugal Portugal

Member

About Paulo Morgado

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalusing DocumentCompleted Pinmemberdakkeh2:58 20 Jan '08  
GeneralRe: using DocumentCompleted PinmemberPaulo Morgado9:12 20 Jan '08  
QuestionSessions get lost Pinmemberrootdial8:38 16 Aug '07  
AnswerRe: Sessions get lost PinmemberPaulo Morgado12:00 16 Aug '07  
GeneralLinks crashing in www.yahoo.com [modified] PinmemberBarry M.8:09 1 Jun '07  
GeneralRe: Links crashing in www.yahoo.com PinmemberPaulo Morgado14:40 2 Jun '07  
GeneralRe: Links crashing in www.yahoo.com PinmemberBarry M.17:41 2 Jun '07  
GeneralRe: Links crashing in www.yahoo.com PinmemberPaulo Morgado1:35 3 Jun '07  
GeneralRe: Links crashing in www.yahoo.com PinmemberBarry M.4:59 3 Jun '07  
GeneralRe: Links crashing in www.yahoo.com PinmemberPaulo Morgado5:52 3 Jun '07  
GeneralRe: Links crashing in www.yahoo.com PinmemberBarry M.13:39 3 Jun '07  
GeneralRe: Links crashing in www.yahoo.com PinmemberPaulo Morgado13:49 3 Jun '07  
GeneralRe: Links crashing in www.yahoo.com PinmemberBarry M.14:01 3 Jun '07  
GeneralRe: Links crashing in www.yahoo.com PinmemberPaulo Morgado12:39 25 Jun '07  
GeneralRe: Links crashing in www.yahoo.com PinmemberBarry M.15:24 25 Jun '07  
GeneralTotal suppressing/management of dialog boxes originated by WebBrowser (or any control) [modified] PinmemberSergey Stoyan8:59 15 Dec '06  
GeneralIDocHostShowUI implementation PinmemberSergey Stoyan14:50 11 Dec '06  
GeneralRe: IDocHostShowUI implementation PinmemberPaulo Morgado4:16 12 Dec '06  
GeneralRe: IDocHostShowUI implementation PinmemberSergey Stoyan4:57 12 Dec '06  
GeneralRe: IDocHostShowUI implementation PinmemberPaulo Morgado11:52 12 Dec '06  
Yes, IDocHostShowUI::ShowMessage is just for window.alert() and window.cofirm().
 
If you are trying to cancel the download, you can use the FileDownloading event (DWebBrowserEvents2::FileDownload).
 
Let me know if you find how to do it. I'm also looking for a way to catch window.showModalDialog and window.showModelessDialog.
 
I tried to extend the WebBrowser control in System.Windows.Forms 2.0 but Microsoft mad it impossible to do so. I'll have to redo everything they did and provide, at least, the same features of this one.
 
Stay tunned in:
WebBrowserControl[^]
 
Paulo Morgado
Portugal - Europe's West Coast

GeneralRe: IDocHostShowUI implementation PinmemberSergey Stoyan5:58 14 Dec '06  
GeneralRe: IDocHostShowUI implementation PinmemberPaulo Morgado13:01 14 Dec '06  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 15 Apr 2010
Article Copyright 2006 by Paulo Morgado
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid