Click here to Skip to main content
Click here to Skip to main content

WebBrowserControl for the .NET Framework 1.1

, 15 Apr 2010
Rate this:
Please Sign up or sign in to vote.
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

Comments and Discussions

 
Generalusing DocumentCompleted Pinmemberdakkeh20-Jan-08 2:58 
GeneralRe: using DocumentCompleted PinmemberPaulo Morgado20-Jan-08 9:12 
QuestionSessions get lost Pinmemberrootdial16-Aug-07 8:38 
AnswerRe: Sessions get lost PinmemberPaulo Morgado16-Aug-07 12:00 
GeneralLinks crashing in www.yahoo.com [modified] PinmemberBarry M.1-Jun-07 8:09 
GeneralRe: Links crashing in www.yahoo.com PinmemberPaulo Morgado2-Jun-07 14:40 
GeneralRe: Links crashing in www.yahoo.com PinmemberBarry M.2-Jun-07 17:41 
Thanks Paulo,
 
I checked into the other solution (which is an extremely impressive wrap of the full browser fucntionality as well as the removal of the mshtml interop), but I have a slight, yet important (to me, anyway) 'nit' that has me preferring your 1.1 wrapping solution, built in 2.0, over the other.
 
This same problem is also found in Microsoft's WebBrowser 2.0 control, and while MSFT confirms its a problem, it appears that they're avoiding a fix to it, since the fix could be complex and dangerous to other functionality.
 
Here's how to produce the issue:
1. Go to maps.yahoo.com (specifically the newer flash version of the site - if it comes up with the older HTML version, make sure you have Flash installed, go back to it, and you'll see the newer version).
2. When the map comes up, click in the map area, then try to navigate this with the arrow keys on the keyboard.
- In normal IE - this works perfectly
- In your browser wrap, even rebuilt in 2.0 - this works perfectly
- In csExWB - it works when you first use the arrow key, and then on subsequent key strokes, the keystrokes are passed to an area outside the browser. I'll bring it up in their forum.
- In System.Windows.Forms.WebBrowser (2.0) - even with a workaround that's been popular with the click events, this arrow key problem stops everything.
 
This keyboard problem seems to happen with all custom C++ ActiveX controls using listboxes and drop-down boxes.
 
If you can find a solution to that named targets problem, then I no longer see any problem with your control, except for maybe the weaker "external" functionality that csWbEx provides, as you said. But the control being fully functional is more important to me than the wrapper...
 
Thanks again for your article and your help,
Barry
 

GeneralRe: Links crashing in www.yahoo.com PinmemberPaulo Morgado3-Jun-07 1:35 
GeneralRe: Links crashing in www.yahoo.com PinmemberBarry M.3-Jun-07 4:59 
GeneralRe: Links crashing in www.yahoo.com PinmemberPaulo Morgado3-Jun-07 5:52 
GeneralRe: Links crashing in www.yahoo.com PinmemberBarry M.3-Jun-07 13:39 
GeneralRe: Links crashing in www.yahoo.com PinmemberPaulo Morgado3-Jun-07 13:49 
GeneralRe: Links crashing in www.yahoo.com PinmemberBarry M.3-Jun-07 14:01 
GeneralRe: Links crashing in www.yahoo.com PinmemberPaulo Morgado25-Jun-07 12:39 
GeneralRe: Links crashing in www.yahoo.com PinmemberBarry M.25-Jun-07 15:24 
GeneralTotal suppressing/management of dialog boxes originated by WebBrowser (or any control) [modified] PinmemberSergey Stoyan15-Dec-06 8:59 
GeneralIDocHostShowUI implementation PinmemberSergey Stoyan11-Dec-06 14:50 
GeneralRe: IDocHostShowUI implementation PinmemberPaulo Morgado12-Dec-06 4:16 
GeneralRe: IDocHostShowUI implementation PinmemberSergey Stoyan12-Dec-06 4:57 
GeneralRe: IDocHostShowUI implementation PinmemberPaulo Morgado12-Dec-06 11:52 
GeneralRe: IDocHostShowUI implementation PinmemberSergey Stoyan14-Dec-06 5:58 
GeneralRe: IDocHostShowUI implementation PinmemberPaulo Morgado14-Dec-06 13:01 

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.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 15 Apr 2010
Article Copyright 2006 by Paulo Morgado
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid