Windows WinForms HTML Editor sample in C# for Visual Studio 2010 参考:http://code.msdn.microsoft.com/windowsdesktop/WinForms-HTML-Editor-01dbce1a
WinForms HTML Editor
The purpose of the Html Editor is to provide Html Editing capabilities within a WinForms control. The control should emulate the operations that are available within a Rich Text control, but have information persisted and restored from an Html BODY element.
The purpose of the Html Editor is to provide a control that allows for Html editing 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.
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.
- Allow for the inserting and removing indentation.
- Allow the inclusion of images along with alternative text and text alignment options.
- Allow for the insertion of web links (Anchor tags), including the definition of the target frame.
- Allow for the insertion of a horizontal line for text separation.
- Provide a Find and Replace mechanisms. This dialog should highlight the appropriate text upon a find, and support a Replace All operation.
- Provide an integrated toolbar to perform the standard text editing functions, and other essential functions (as listed in the above points).
- Allow for the Insert mode (overwrite), word wrapping options to be toggled, and the visibility of scroll bars to be defined.
- Allow the use of context menus that include all the required text formatting commands. The context menu should be sensitive to the user’s selection.
- Allow for the insert, removal, and property definition of tables.
Body Properties
- 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.
- Support the inclusion of Headings and Formatted blocks of text. This operation should be able to be performed in reverse; set to
Normal style.
- Have the ability to define the default body background and foreground colors.
- Allow for the ability of the Html content to be viewed or edited directly.
- Allow for the pasting of Text and Html Markup.
External Behavior
- 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.
- Allow for the ability to ensure all links are forwarded to a new browser window; and not rendered within the window containing
the original link.
- Allow a document to be loaded by a given URL.
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
Here is the C# Public API
|