"A few years ago I wrote a WinForms HTML Editor. As I have been working in WinForms again it seemed appropriate to post the code up to a new location:
The purpose of the Html Editor is to provide Html Editing capabilities within a WinForms control; satisfying the requirements of input for rich text layouts and simple portal type information. Examples of the former are case where the Rich Text control would normally be utilized; documentation, complex descriptions where text formatting is required, correspondences, bulletins, etc. Examples of the latter case are such items as dashboards; news clips, announcements, company references, etc. These are defined by cases where complex layouts are required that may include images and links.
The control emulates the operations that are available within a Rich Text control, but have information persisted and restored using an Html BODY element.
High level design goals are:
- Provides robust WYSIWYG editing capabilities whose contents are persisted in HTML format.
- Is easily reusable in other projects.
- Provides methods for saving HTML files to and loading files from disk (with the appropriate security demands).
The basic operations of the control are thus defined as:
Standard Text Editing
- Support basic formatting commands such as Bold, Italic, Underline, Strikeout, Font Name, Font Size, Font Color, Justification (Left, Right, and Center), Bullets and Number Lists. Dialogs should be presented to the user for modifying Font and Color attributes.
- Provide for standard Cut, Copy, Paste, Undo, Redo, Select All, and commands.
- Have the ability to simply set the text of the document body, the inner text of an Html Document; a browsable designer property.
- Allow for the assignment of the complete Body element (Body outer Html), preserving and body properties. Also allow for the
assignment of the Body contents, Body inner Html.
- Allow a reference to a stylesheet to be applied to the document at runtime. The purpose is to allow the definition of a corporate wide stylesheet that all documents should reference for standardizing fonts, colors, etc.
- Allow a reference to a script source file to be applied to the document at runtime. The purpose is to allow the use of a corporate script file that can be used for handling links requiring programmatic redirection.
HTML Editor Non Goals
The Html Editor is not designed to provide similar functionality to Html Editor Products. For complex layout requiring Styles, Absolute Positing, Frames, Multi-Media, etc, these products should be utilized.
Operations that the control does not support are thus defined as:
- Support is only included for a single Font selection and not Font Families.
- Support for 2D-Position, Absolute Position, and Live Resize is not included.
- Multiple Selections of items is not supported and all operations are based on a single selected control.
- Simple Font properties are used rather than style attributes. The inclusion of style attributes brings around complexity regarding the use of Span tags.
- There was the option to have the control be Tab driven; supporting Design, Edit Html, and Preview. This would then have made the control look more like a fully-functional Html editor rather than a replacement to the Rich Text Box.
Here is a complete set of documentation: Html Editor Application.pdf
This control (for which you get the source also) has a 30 page doc... Shiney!
Here's a snap of the source, control and sample app, in VS;