Articles in this section
Category / Section

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

1 min read

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

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied