Can I set text properties for specific words in an EditControl

Does EditControl allow for setting text properties for specified sub-text (strings or words within the entire text). I'd like to programmatically set a color or font for specific key words within an EditControl.

1 Reply

DR Durga Rajan Syncfusion Team February 22, 2018 12:40 PM UTC

Hi Mike, 

Thanks for contacting Syncfusion support. 

Query : Does EditControl allow for setting text properties for specified sub-text (strings or words within the entire text). I'd like to programmatically set a color or font for specific key words within an EditControl. 

We can give different colorings to text based on the Format(keywords, literals, comments…etc) through CustomLanguage. We have checked your query and prepared sample which tries to meet your requirement. In this sample we have changed the fore color of the Text based on the Format name in the Format collection. 

Code example : 

Format snippet: 

        private List<EditFormats> formats = new List<EditFormats>() 
        { 
            new EditFormats() { Foreground = Brushes.Blue, FormatName = "KeywordFormat" }, 
             new EditFormats() { Foreground = Brushes.Green, FormatName = "CommentFormat" },            
               new EditFormats() { Foreground = Brushes.Navy, FormatName = "OperatorFormat" },                           
        }; 

Lexes collection : 
 
private List<Lexem> lexems = new List<Lexem>() 
        { 
            //   // Define the lexeme to match the one character in the word 
            new Lexem() { StartText = "class",LexemType = EditTokenType.CodeSnippet, FormatName = "KeywordFormat" }, 
            new Lexem() { StartText = "def", LexemType = EditTokenType.CodeSnippet, FormatName = "KeywordFormat" }, 
            new Lexem() { StartText = "#", EndText = "#", IsRegex = false, IsMultiline = false, LexemType = EditTokenType.Comment, FormatName = "CommentFormat" }, 
            new Lexem() { StartText = "and", ContainsEndText=false, IsRegex = false, LexemType = EditTokenType.Keyword, FormatName = "KeywordFormat" }, 
            new Lexem() { StartText = ")", ContainsEndText=false, LexemType = EditTokenType.Operator, FormatName = "OperatorFormat" }, 
            new Lexem() { StartText = "(", ContainsEndText=false, LexemType = EditTokenType.Operator, FormatName = "OperatorFormat" }, 
            new Lexem() { StartText = "}", ContainsEndText=false, IsRegex = false, LexemType = EditTokenType.Operator, FormatName = "OperatorFormat" }, 
            new Lexem() { StartText = "{", ContainsEndText=false, IsRegex = false, LexemType = EditTokenType.Operator, FormatName = "OperatorFormat" }, 
            new Lexem() { StartText = "]", ContainsEndText=false, IsRegex = false, LexemType = EditTokenType.Operator, FormatName = "OperatorFormat" }, 
            new Lexem() { StartText = "[", ContainsEndText=false, IsRegex = false, LexemType = EditTokenType.Operator, FormatName = "OperatorFormat" }, 
            new Lexem() { StartText = ";", ContainsEndText=false, IsRegex = false, LexemType = EditTokenType.Operator, FormatName = "OperatorFormat" }, 
            new Lexem() { StartText = "*", ContainsEndText=false, IsRegex = false, LexemType = EditTokenType.Operator, FormatName = "OperatorFormat" }, 
        }; 
 

Please download the sample for the same from below location, 


Please get back to us with more details like sample, if you are facing any issues with the above sample. This would help us to provide solution at earliest. 

Regards, 
Durga S. 


Loader.
Up arrow icon