Click here to Skip to main content
Licence CPOL
First Posted 17 Nov 2009
Views 39,350
Downloads 9,027
Bookmarked 104 times

Zeta HTML Edit Control

By | 2 Jun 2011 | Article
A small wrapper class around the Windows Forms 2.0 WebBrowser control

Introduction

This article presents you a small wrapper class around the Windows Forms 2.0 WebBrowser control.

Features

The wrapper is no rocket science but provides some features I struggled with in the past. We use the control in several of our own (internal) applications.

Some of the features include:

  • Enable the setting of text even when the control is not yet fully initialized
  • Allow pasting of images from the clipboard
  • Provide an alternative context menu for applying formatting options
  • Optionally directly edit the underlying HTML source code
  • Translate resources in English and German
  • Interface IExternalInformationProvider for externally persisting and restoring settings
  • Provide standard CSS in the control; usually you do not need to define your own CSS

Using the Code

To include the code in your own project, simply include the "ZetaHtmlEditControl.dll" assembly into your project.

Add the assembly to your Visual Studio .NET 2008 Windows Forms Designer Toolbox if you want to be able to drag the ExtendedWebBrowser control to your forms. Alternatively create and initialize an instance of the ExtendedWebBrowser control by code.

Setting HTML

To put HTML from your code into the control, assign the HTML code to the ExtendedWebBrowser.DocumentText property. You do not have to pass a complete HTML document with HEAD and BODY tags but only the actual content that you would write inside the BODY tag.

Getting the HTML

To read out the HTML from the control, call the ExtendedWebBrowser.GetDocumentText(string folderPath) method. The method takes one parameter "folderPath" that tells the control where to store newly passed images from the clipboard.

Summary

This article quickly introduced a wrapper around the Windows Forms 2.0 WebBrowser control that adds some extra functions to make it more usable in a real-world-application. Feel free to copy, modify or extend the control to match your own requirements.

To ask questions, suggest features or provide other comments, please use the comments section at the bottom of this article.

History

  • 2011-06-02 - Added support for inserting and editing tables. Added new user control that has a toolbar (see screenshot) that you can switch on and off from code.
  • 2011-03-16 - Updated for and tested with the latest Internet Explorer 9 (RTM). If you do experience AccessViolation exceptions when working with this control, please read this MSDN blog posting that suggests to add a custom build step
    "$(DevEnvDir)..\tools\vsvars32.bat"
    editbin.exe /NXCOMPAT:NO "$(TargetPath)"
  • 2011-02-26 - Update to (hopefully) make the control work with Internet Explorer 9 RC work again. See this Stack Overflow posting for details. I've included a mini web server with the control to serve the texts from this server, instead of setting it directly. It should be 100% transparent to the user of the code.
  • 2009-11-18 - First public release to CodeProject.com

License

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

About the Author

Uwe Keim

Chief Technology Officer
Zeta Producer Desktop CMS
Germany Germany

Member

Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He is also teached programming to students at the local university.
 
In his free time, he does climbing, running and mountain biking. You can watch him most of the day (and probably night) programming.
 
Some cool, free software from us:
 
Free Test Management Software - Intuitive, competitive, Test Plans. Download now!  
Homepage erstellen - Intuitive, very easy to use. Download now!  
Send large Files online for free by Email
Some random fun stuff in German


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
GeneralMy vote of 5 PinmemberEngone9:40 14 Dec '11  
QuestionFont Change PinmemberezbUltra0:30 3 Nov '11  
QuestionAssembly load issue PinmemberEric Legault5:51 13 Oct '11  
AnswerRe: Assembly load issue PinsitebuilderUwe Keim6:43 13 Oct '11  
Question2 Questions (httpserver.dll) PinmemberMartin Poehler5:21 21 Jul '11  
AnswerRe: 2 Questions (httpserver.dll) PinsitebuilderUwe Keim21:29 22 Jul '11  
GeneralSome questions about the control Pinmembergreg_quinn0:55 13 Jun '11  
GeneralRe: Some questions about the control PinsitebuilderUwe Keim18:58 13 Jun '11  
GeneralRe: Some questions about the control Pinmembergreg_quinn2:59 15 Jun '11  
GeneralRe: Some questions about the control PinsitebuilderUwe Keim3:02 18 Jun '11  
GeneralRe: Some questions about the control Pinmembergreg_quinn3:13 15 Jun '11  
QuestionHow to insert an image? Pinmemberseanzcan3:53 7 Jun '11  
GeneralGo Zeta Go Pinmembersam.hill10:27 2 Jun '11  
GeneralRe: Go Zeta Go PinsitebuilderUwe Keim18:43 2 Jun '11  
GeneralMy vote of 5 PinmemberFilip D'haene5:42 2 Jun '11  
GeneralRe: My vote of 5 PinsitebuilderUwe Keim5:43 2 Jun '11  
GeneralThis is cool PinmvpSacha Barber22:43 15 Mar '11  
GeneralRe: This is cool PinsitebuilderUwe Keim23:35 15 Mar '11  
QuestionWeb server overkill ? PinmemberTrendyTim7:19 1 Mar '11  
AnswerRe: Web server overkill ? PinsitebuilderUwe Keim7:41 1 Mar '11  
GeneralMy vote of 5 Pinmembersam.hill7:12 26 Feb '11  
GeneralRe: My vote of 5 PinsitebuilderUwe Keim9:41 26 Feb '11  
GeneralRe: My vote of 5 [modified] Pinmemberwknopf4:42 28 Feb '11  
GeneralRe: My vote of 5 PinsitebuilderUwe Keim9:03 28 Feb '11  
GeneralIE9 breaks control Pinmemberwknopf11:23 16 Feb '11  

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
Web01 | 2.5.120517.1 | Last Updated 2 Jun 2011
Article Copyright 2009 by Uwe Keim
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid