Enhances a RichTextBox with language-specific syntax highlighting, plus some additional keyboard formatting controls.
For a list of all members of this type, see SyntaxHilightTextBox Members.
System.Object
MarshalByRefObject
Component
Control
TextBoxBase
RichTextBox
SyntaxHilightTextBox
OracleSyntaxHilightTextBox
SqlServerSyntaxHilightTextBox
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
Language keywords, comments (both bracketed and end-of-line), and strings are each highlighted in a different color. The colors for each are selectable via properties, as are the comment tokens, the string delimiter(s), and the list of language keywords. By default the list of keywords is empty; you must populate the WordList property with a list of keywords to highlight. Then simply use that subclass instead of a RichTextBox on a Windows Form.
Besides the description here, I have also published an article discussing the practical uses of this tool -- .NET Building Blocks: Build a RichTextBox-Based Syntax-Highlighting Editor and IDE -- available on the DevX online magazine.
This user control may be configured to operate automatically or manually via the AutoHilight property. The default is manual, meaning that no highlighting will be performed until you invoke RefreshHilight. One suggested implementation is to call RefreshHilight upon loading a file as well as providing a button for the user to invoke it on demand. Alternatively, set AutoHilight to true and the control will re-highlight after the user stops typing for a specified time (via the RefreshDelay property). (While this works, there is an annoying flash/scroll artifact from the refresh that I have not resolved yet.)
There are some additional methods provided for a finer level of control. ColorWords and ColorWord allow you to highlight an arbitrary list of words or an arbitrary single word, respectively. CommentSelection and UncommentSelection allow you to mark off a section of text as a comment by inserting the endOfLineCommentMark at the front of each line in the current selection, or to remove the mark, respectively.
Just as the base RichTextBox class has built-in support for certain keystrokes (Control-C for copy, Control-V for paste, etc.) the SyntaxHilightTextBox adds several more:
Since CleanCode 0.9.13.
Namespace: CleanCodeControls.Forms
Assembly: CleanCodeControls (in CleanCodeControls.dll)
SyntaxHilightTextBox Members | CleanCodeControls.Forms Namespace