Click here to Skip to main content
15,867,308 members
Articles / Desktop Programming / Windows Forms

Zeta HTML Edit Control

Rate me:
Please Sign up or sign in to vote.
4.94/5 (60 votes)
9 Jul 2013CPOL3 min read 210.7K   20.8K   183   83
A small wrapper class around the Windows Forms 2.0 WebBrowser control
Image 1

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 and external) applications, e.g. our Test Management tool

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
  • Allows for resizing the images within the editor with the mouse 
  • Provide an alternative context menu for applying formatting options
  • Optionally directly edit the underlying HTML source code
  • Translated 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

  • 2013-07-09 - You now also find the project on GitHub
  • 2013-05-20 - Images inside the edit control can now be resized proportionally to make them smaller. When persisting the images, they are actually resized on disk, too.
  • 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)


Written By
Chief Technology Officer Zeta Software GmbH
Germany Germany
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 has also teached programming to students at the local university.

➡️ Give me a tip 🙂

In his free time, he does climbing, running and mountain biking. In 2012 he became a father of a cute boy and in 2014 of an awesome girl.

Some cool, free software from us:

Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans.  
Homepage erstellen - Intuitive, very easy to use.  
Offline-Homepage-Baukasten

Comments and Discussions

 
QuestionMany Thanks Pin
.dan.g.3-Dec-18 15:50
professional.dan.g.3-Dec-18 15:50 
GeneralMy vote of 5 Pin
Ktn K Thkkr5-Nov-15 6:36
professionalKtn K Thkkr5-Nov-15 6:36 
QuestionImages saved with no extension Pin
Dung Tran18-Mar-15 16:12
Dung Tran18-Mar-15 16:12 
QuestionTol solve the problem of how to get text of HTML or how to avoid get "" (nothing) Pin
Alejandro Barrada11-Dec-14 1:51
Alejandro Barrada11-Dec-14 1:51 
I found the solution, load the comonent HTMLEditUserControl, then on forms onload set :
ZetaHTMLEditContrl.HtmlEditControl.DocumentText = ""
Now you can write text and retrieve using
ZetaHTMLEditContrl.HtmlEditControl.getdocumenttext

Alejandro
QuestionHow can I delete or clean the current text Pin
Member 110588294-Sep-14 4:26
Member 110588294-Sep-14 4:26 
QuestionCan't add to toolbox in VS2012 Pin
Daniel Borson31-Jan-14 11:37
Daniel Borson31-Jan-14 11:37 
QuestionNot working in vs2013 Pin
simplex223-Nov-13 11:42
simplex223-Nov-13 11:42 
GeneralRe: Not working in vs2013 Pin
stelios198419-May-14 2:49
stelios198419-May-14 2:49 
AnswerRe: Not working in vs2013 Pin
dev.mostafa29-Sep-14 3:48
dev.mostafa29-Sep-14 3:48 
AnswerRe: Not working in vs2013 Pin
Alejandro Barrada11-Dec-14 1:46
Alejandro Barrada11-Dec-14 1:46 
QuestionSpell check Pin
Member 1039935913-Nov-13 5:16
Member 1039935913-Nov-13 5:16 
QuestionDisabling shortcuts Alt + a etc. Pin
Member 81657438-Oct-13 22:15
Member 81657438-Oct-13 22:15 
QuestionMaking it readonly without disabling scrollbars Pin
Member 99171342-Sep-13 18:52
Member 99171342-Sep-13 18:52 
QuestionHow to save html from HtmlEditUserControl1 to file Pin
elpaez17-Aug-13 1:50
elpaez17-Aug-13 1:50 
AnswerRe: How to save html from HtmlEditUserControl1 to file Pin
Member 99171342-Sep-13 19:13
Member 99171342-Sep-13 19:13 
GeneralRe: How to save html from HtmlEditUserControl1 to file Pin
elpaez2-Sep-13 19:59
elpaez2-Sep-13 19:59 
GeneralMy vote of 5 Pin
Danilo Dev.8-Jul-13 3:57
Danilo Dev.8-Jul-13 3:57 
QuestionI added Font Name and Size Pin
trantrum11-Jun-13 3:29
professionaltrantrum11-Jun-13 3:29 
PraiseRe: I added Font Name and Size Pin
.dan.g.13-Dec-18 15:13
professional.dan.g.13-Dec-18 15:13 
QuestionReally nice but where is the font and font size? Pin
trantrum10-Jun-13 8:08
professionaltrantrum10-Jun-13 8:08 
GeneralMy vote of 4 Pin
JRoger_1-Jun-13 6:21
JRoger_1-Jun-13 6:21 
QuestionLove it... Pin
Oleg Shilo21-May-13 2:43
Oleg Shilo21-May-13 2:43 
AnswerRe: Love it... Pin
Uwe Keim21-May-13 3:39
sitebuilderUwe Keim21-May-13 3:39 
GeneralRe: Love it... Pin
Oleg Shilo21-May-13 3:56
Oleg Shilo21-May-13 3:56 
GeneralRe: Love it... Pin
Oleg Shilo21-May-13 21:02
Oleg Shilo21-May-13 21:02 

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

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