Tim Anderson's ITWriting

The HtmlEditor - a C# control that wraps MSHTML

 

 

The HTMLEditor

The HTMLEditor control is a wrapper for MSHTML, the rendering portion of Internet Explorer (and IE's largest single component). Now revised for .NET 2.0, with no dependency on the Microsoft.mshtml interop assembly. Code is now published in a Subversion repository.


The HTMLEditor is written in C#. Unlike the .Net webbrowser control, in versions prior to .NET 2.0, this is not an ActiveX control. Rather it is an ActiveX Document. Even if you are not interested in MSHTML, you may be interested in the HTMLEditor as an example of advanced .NET / COM interop. It's also not suitable for embedded web browsing - use the ActiveX for that.

However, it is a pretty cool control. It allows editing as well as read-only display, supports advanced features like print templates and edit designers, gives easy access to the HTML DOM, and lets you load HTML simply by assigning a string to a property.

I've posted the code for two reasons. First, as a thank-you to those who made it possible by posting their code (esp. Lutz Roeder). Second, in the hope that the community can improve it further :-). Updates will be posted here.

The latest version control no longer requires the Microsoft.Mshtml.dll Primary Interop Assembly. The main reason is ease of deployment: this large file is not part of the standard dotnetfx.exe runtime. It's also not been updated for .NET 2.0, which makes me suspect it is deprecated.

There is an open discussion forum which is intended to be the home point for comments, queries and suggestions, so please use it for your comments and questions.

Download the HTMLEditor for Visual Studio 2005 (.NET 2.0) (ZIP file)

You are recommended to grab the latest code from the Subversion repository rather than using the above ZIP file.

Download the HTMLEditor for Visual Studio 2005 (.NET 2.0) - old version with Microsoft.Mshtml dependency.

Download the HTMLEditor for Visual Studio 2003 (.NET 1.1)

If none of the COM stuff makes sense, try this book:

.NET and COM by Adam Nathan

Click here for other C# titles

Have a look at the home page for other .Net articles (and other topics).

 

Copyright ©2004 Tim Anderson