Articles in this section
Category / Section

How to highlight the text while it end with some specific character?

1 min read

We can customize the color of line if it is end with specific character. It can be achieved by setting the lexem in custom config file.

 

Lexem

It contains rules for parsing the text. There are two attributes to specify the format of the lexem.

 

  1. Type: Type is used for standard predefined types of the lexems.
  2. FormatName: The FormatName is used only when Type is Custom.

 

Here we have highlighted the line if end with “!” character. The following code demonstrates the same.

 

XML

<!-- Configuaration -->

 

<ConfigLanguage name="new" CaseInsensitive="true">

 

<formats>

 

<!-- Highlight color -->

 

<format name="String" Font="Courier New, 13pt, style=Bold" FontColor="Green" />

 

</formats>

 

<extensions>

 

<extension>new</extension>

 

</extensions>

 

<lexems>

 

<!-- Set the Required Highlight format -->

 

<lexem BeginBlock="[A-z\s]+\!" IsBeginRegex="true"  Type="String"/>

 

</lexems>

 

<splits>

 

<split IsRegex="true">[A-z\s]+\!</split>

 

</splits>

 

</ConfigLanguage>

 

 

C#

//Define config file path
 
private string configPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\..\\..\\Config.xml";
 
public Form1()
{ 
 
InitializeComponent();
 
editControl1.Text = "Hello World!" + Environment.NewLine + "Welcome" + Environment.NewLine + "Have a Good Day!";
 
// External configuration file.
 
this.editControl1.Configurator.Open(configPath);
 
// Apply the configuration defined in the configuration file.
 
this.editControl1.ApplyConfiguration("new");
 
}

 

Screenshot

 

Showing different format of text in EditControl

 

Sample: SyntaxEditorSample

 



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