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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How can I programmatically perform syntax highlighting in the EditControl ?


It is possible to create configuration settings programmatically using ISnippetFormat and ConfigLexem class. Please refer to the attached sample and the code snippets below that illustrates this.


public Form1()



 IConfigLanguage language = this.editControl1.Configurator.CreateLanguageConfiguration("New");

 Split s1 = new Split("/*");

Split s2 = new Split("*/");




 ISnippetFormat keyword = this.editControl1.Language.Add("Keyword");

keyword.Font = new Font("Arial", 10, FontStyle.Regular);

keyword.FontColor = Color.Blue;

 ISnippetFormat comment = this.editControl1.Language.Add("Comment");

comment.Font = new Font("Arial", 10, FontStyle.Regular);

comment.FontColor = Color.Green;

 ISnippetFormat text = this.editControl1.Language.Add("Text");

text.FontColor = Color.Brown;

text.Font = new Font("Arial", 10);

 ConfigLexem keywordlexem1 = new ConfigLexem("private", "", FormatType.Custom, false);

keywordlexem1.FormatName = "Keyword";


 ConfigLexem keywordlexem2 = new ConfigLexem("int", "", FormatType.Custom, false);

keywordlexem2.FormatName = "Keyword";


 ConfigLexem configLex = new ConfigLexem("this", "", FormatType.Custom, false);

configLex.FormatName = "Keyword";


 ConfigLexem commentlexem = new ConfigLexem("/*","*/", FormatType.Custom,true);

commentlexem.FormatName = "Comment";

commentlexem.OnlyLocalSublexems = true;

      ConfigLexem configLex1 = new ConfigLexem("[a-z|A-Z]*", "", FormatType.Custom, false);

configLex1.IsBeginRegex = true;

configLex1.FormatName = "Text";



 this.editControl1.Text = "this is the first line\nthis is the second line\nthis is the third line\n\n/* Sample */\n\nprivate int";



 Public Sub New()

 ' This call is required by the Windows Form Designer.


Dim language As IConfigLanguage = Me.EditControl1.Configurator.CreateLanguageConfiguration("New")

 Dim s1 As Split = New Split("/*")

Dim s2 As Split = New Split("*/")




 Dim keyword As ISnippetFormat = Me.EditControl1.Language.Add("Keyword")

keyword.Font = New Font("Arial", 10, FontStyle.Regular)

keyword.FontColor = Color.Blue

 Dim comment As ISnippetFormat = Me.EditControl1.Language.Add("Comment")

comment.Font = New Font("Arial", 10, FontStyle.Regular)

comment.FontColor = Color.Green

 Dim text As ISnippetFormat = Me.EditControl1.Language.Add("Text")

text.FontColor = Color.Brown

text.Font = New Font("Arial", 10)

 Dim keywordlexem1 As ConfigLexem = New ConfigLexem("private", "", FormatType.Custom, False)

keywordlexem1.FormatName = "Keyword"


 Dim keywordlexem2 As ConfigLexem = New ConfigLexem("int", "", FormatType.Custom, False)

keywordlexem2.FormatName = "Keyword"


 Dim configLex As ConfigLexem = New ConfigLexem("this", "", FormatType.Custom, False)

configLex.FormatName = "Keyword"


 Dim commentlexem As ConfigLexem = New ConfigLexem("/*", "*/", FormatType.Custom, True)

commentlexem.FormatName = "Comment"

commentlexem.OnlyLocalSublexems = True

 Dim configLex1 As ConfigLexem = New ConfigLexem("[a-z|A-Z]*", "", FormatType.Custom, False)

configLex1.IsBeginRegex = True

configLex1.FormatName = "Text"



 Me.EditControl1.Text = "this is the first line" & Constants.vbLf & "this is the second line" & Constants.vbLf & "this is the third line" & Constants.vbLf + Constants.vbLf & "/* Sample */" & Constants.vbLf + Constants.vbLf & "private int"

 ' Add any initialization after the InitializeComponent() call.

 End Sub

End Class

Article ID: Published Date: Last Revised Date: Platform: Control:
307 04/30/2011 07/10/2014 WinForms EditControl
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Please sign in to access our KB

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

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