Skip to content

Implement syntax highlighting for C# and VB code displayed in the Rich Text Editor.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/rich-text-editor-highlight-syntax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rich Text Editor for WinForms - Implement ISyntaxHighlightService to Highlight C# and VB Code Syntax

The Rich Text Editor supports ISyntaxHighlightService that allows you to implement syntax highlighting for a document displayed in the control. This example demonstrates how to highlight its source code (C# and VB). The project uses the DevExpress CodeParser library to parse the code into tokens according to the syntax elements of the programming language.

Rich Text Editor - Highlight Code Syntax

Implementation Details

  1. Declare a custom class that implements ISyntaxHighlightService. In the class constructor, specify colors for different code element categories (keywords, comments, strings, and so on). This example uses colors of the current application skin.
  2. Implement the ISyntaxHighlightService.Execute method. Within the method, use parsers from the DevExpress CodeParser library to parse C# and VB source code into tokens.
  3. Convert tokens to the SyntaxHighlightToken objects and specify format settings for each token.
  4. Pass the list of SyntaxHighlightToken objects to the SubDocument.ApplySyntaxHighlight method to enable syntax highlighting in the document.
  5. Call the RichEditControl.ReplaceService<T> method to register the custom ISyntaxHighlightService implementation.

Files to Look At

Form1.cs (VB: Form1.vb)

Documentation

Highlight Document Syntax

More Examples

How to: Create Syntax Highlight Tokens to Highlight T-SQL Language Syntax

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Implement syntax highlighting for C# and VB code displayed in the Rich Text Editor.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •