)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create ConfigLexem for Comment statement programmatically in WinForms SyntaxEditor (EditControl)?

Platform: WinForms |
Control: EditControl |
Published Date: April 30, 2011 |
Last Revised Date: December 12, 2019

Configuration for custom comments

The configuration settings for custom comments can be created as outlined in the steps below.

1. Create an ISnippetFormat for the custom comment.

2. Create a ConfigLexem associated with the comment.

3. Add the ConfigLexem to the EditControl’s Language.Lexems collection.

4. Add the ConfigLexems which are used as sub-lexems to the parent ConfigLexem.SubLexems collection.

5. Create two separate Split entries for the lexems used for opening and closing the comments, i.e., ‘/*’ and ‘*/’.

C#

// Multi-character splits should be added to make tokenizer read them as a single word.
currentConfigLanguage.Splits.Add( "/*" );
currentConfigLanguage.Splits.Add( "*/" );
ConfigLexem commentLexem = new ConfigLexem();
commentLexem.BeginBlock = "/*";
commentLexem.EndBlock = "*/";
commentLexem.Type = FormatType.Custom;
commentLexem.FormatName = "Comment";
commentLexem.OnlyLocalSublexems = true;
commentLexem.IsComplex = true;
commentLexem.IsCollapsable = true;
commentLexem.CollapseName = "/*...*/";
ConfigLexem commentSubLexem = new ConfigLexem();
commentSubLexem.BeginBlock ="\\n";// or @"\n"
commentSubLexem.IsBeginRegex = true;
commentSubLexem.Type = FormatType.Custom;
commentSubLexem.FormatName = "Comment";
commentSubLexem.ParentConfig = commentLexem;
commentLexem.SubLexems.Add(commentSubLexem);
// Configuration lexems can not be placed into two or more containers
currentConfigLanguage.Lexems.Add(commentLexem);
currentConfigLanguage.ResetCaches();
// Configuration should be applied just once, and just after it is completely created.
this.editControl1.ApplyConfiguration(currentConfigLanguage);

 

VB

' Multi-character splits should be added to make tokenizer read them as a single word.
currentConfigLanguage.Splits.Add("/*")
currentConfigLanguage.Splits.Add("*/")
Dim commentLexem As ConfigLexem = New ConfigLexem()
commentLexem.BeginBlock = "/*"
commentLexem.EndBlock = "*/"
commentLexem.Type = FormatType.Custom
commentLexem.FormatName = "Comment"
commentLexem.OnlyLocalSublexems = True
commentLexem.IsComplex = True
commentLexem.IsCollapsable = True
commentLexem.CollapseName = "/*...*/"
Dim commentSubLexem As ConfigLexem = New ConfigLexem()
commentSubLexem.BeginBlock ="\n" ' or @"\n"
commentSubLexem.IsBeginRegex = True
commentSubLexem.Type = FormatType.Custom
commentSubLexem.FormatName = "Comment"
commentSubLexem.ParentConfig = commentLexem
commentLexem.SubLexems.Add(commentSubLexem)
' Configuration lexems can not be placed into two or more containers
currentConfigLanguage.Lexems.Add(commentLexem)
currentConfigLanguage.ResetCaches()
' Configuration should be applied just once, and just after it is completely created.
Me.editControl1.ApplyConfiguration(currentConfigLanguage)

 

Reference link: https://help.syncfusion.com/windowsforms/syntax-editor/syntax-highlighting#splits

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
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
Live Chat Icon