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

How do I programmatically change the default text formatting using IConfigLanguage / ISnippetFormat / ConfigLexem

I am trying to implement custom syntax highlighting programmatically as shown here:

https://help.syncfusion.com/windowsforms/syntax-editor/syntax-highlighting#configure-custom-language-using-code

I can't work out how to simply change the default text color. Using the Config.xml method you can accomplish this with:

<formats>
      <format name="Text" Font="Consolas, 12pt"/>
</formats>

What is the equivalent of this using IConfigLanguage / ISnippetFormat / ConfigLexem?

I tried this:

ISnippetFormat thetext = this.editControl1.Language.Add("text");
thetext.FontColor = Color.Blue;
thetext.Font = new Font("Consolas", 12);


But it's not working for me. I think it's because I need to assign this custom format to something as well?


From what I understand, the below code would change all occurances of the word "stuff" to have a back color of blue:

IConfigLanguage currentConfigLanguage = this.editControl1.Configurator.CreateLanguageConfiguration("Custom_Language");
this.editControl1.ApplyConfiguration(currentConfigLanguage);

ISnippetFormat formatMethod = this.editControl1.Language.Add("BlueBackColor");
formatMethod.Font = new Font("Consolas", 12);
formatMethod.BackColor = Color.Blue;

ConfigLexem stuff = new ConfigLexem("stuff", "", FormatType.Custom, false);
stuff.FormatName = "BlueBackColor";
this.editControl1.Language.Lexems.Add(stuff);

this
.editControl1.Language.ResetCaches();

But what I don't understand is how I can apply a custom ISnippetFormat instance to all default text. The examples only show how to link a format method to a ConfigLexem.

Here are my questions:

  1. How do I change the default text color of EditControl programmatically?
  2. What are ALL the ways I can use an ISnippetFormat other than with ConfigLexem?

Thank you for any help. I am new to C# so apologies if this is too basic. I've tried everything I can think of.

1 Reply

KA Karthick Arjunan Syncfusion Team March 17, 2023 12:02 PM UTC

Hi Joseph,


We have published a knowledge base article for how to change the default text formatting in the edit control, which can assist you in modifying the default text format and also include a sample in the article. You can refer to the following link for more information: 

 

KB Link : https://www.syncfusion.com/kb/11105/how-to-programmatically-configure-syntax-highlighting-in-winforms-syntaxeditor

 

Please let us know if you require any further assistance on this.


Regards
Karthick Arjunan


Loader.
Live Chat Icon For mobile
Up arrow icon