Zeta HTML Edit 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-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
发表评论
M9b699 If some one wishes expert view on the topic of running a blog after
2K1jOn Its hard to find good help I am regularly saying that its hard to find good help, but here is
X9wlEr Really informative post.Really looking forward to read more. Really Cool.
lJqV0p Im thankful for the post. Will read on...
RqHQUa Major thanks for the article.Thanks Again. Really Great.
x7Upl6 Very neat article post.Much thanks again. Cool.