We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to programmatically configure syntax highlighting in WinForms SyntaxEditor?

Platform: WinForms |
Control: EditControl |
Published Date: March 3, 2020 |
Last Revised Date: March 18, 2020 |
Product Version:

WinForms SyntaxEditor allows to configure syntax formatting of built-in supported languages and also it allows to create and configure new languages using xml and programmatically. This article explains how to programmatically configure syntax highlighting after custom configuration loaded using EditControl.Configurator.Open.

In SyntaxEditor, you can change the font style, font family, font size and font color of syntax highlighting by creating ConfigLexem and adding it to EditControl.Language.Lexems collection.

Creating custom configuration lexems

Follow below steps for creating custom configuration

  1. Create new format using EditControl.Language.Add method.
  2. Configure font settings for newly created format.
  3. Create ConfigLexem and set the about create format and configure its attribute. For example, in the below code two lexem are created. One lexem to format the string A to Z and another formats the numbers 1 to 9 using RegEx.
  4. Add the configured lexem to active Language configuration.


            //creating new format
            ISnippetFormat keywordFormat = this.editControl1.Language.Add("Keyword");
            //Configuring newly created format
            keywordFormat.FontColor = Color.Red;
            keywordFormat.Font = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Regular);
            //creating new ConfigLexem
            ConfigLexem configLex = new ConfigLexem("[A-Z]+", "", FormatType.Custom, false);
            configLex.IsBeginRegex = true;
            configLex.IsEndRegex = true;
            configLex.FormatName = "Keyword";
            //creating new format
            ISnippetFormat keywordFormat1 = this.editControl1.Language.Add("Keyword1");
            // Configuring newly created format
            keywordFormat1.FontColor = Color.Green;
            keywordFormat1.Font = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Bold);
            //creating new ConfigLexem
            ConfigLexem configLex1 = new ConfigLexem("[1-9]+", "", FormatType.Custom, false);
            configLex1.IsBeginRegex = true;
            configLex1.IsEndRegex = true;
            configLex1.FormatName = "Keyword1";
            //adding ConfigLexems to language


SyntaxEditor Font customization


Sample : View Sample in GitHub

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile