How to highlight background tag in HTML with WinForms Editor?
Background settings
It is possible to highlight the background of certain tags in HTML or XML using the EditControl's ability to add runtime configuration. We have considered the following tags as an example here -. The background will be highlighted with a yellow color just like in the WinForms files (aspx/ascx). Please refer to the following code snippets for information in this regard.
C#
this.editControl1.ApplyConfiguration(KnownLanguages.HTML); // Create a format and set its attributes ISnippetFormat formatMethod = this.editControl1.Language.Add("CodeBehind"); formatMethod.FontColor = Color.Black; formatMethod.Font = new Font("Courier New",10); formatMethod.BackColor = Color.Yellow; // Create a lexem that belongs to this format ConfigLexem configLex = new ConfigLexem("<%@", "%>", FormatType.Custom, false); configLex.IsBeginRegex = false; configLex.IsEndRegex = false; configLex.ContinueBlock = ".+"; configLex.IsContinueRegex = true; configLex.FormatName = "CodeBehind"; this.editControl1.Language.Splits.Add("<%@"); this.editControl1.Language.Splits.Add("%>"); // Add it to the current language's lexems collection this.editControl1.Language.Lexems.Add(configLex); this.editControl1.Language.ResetCaches();
VB
Me.editControl1.ApplyConfiguration(KnownLanguages.HTML) ' Create a format and set its attributes Dim formatMethod As ISnippetFormat = Me.editControl1.Language.Add("CodeBehind") formatMethod.FontColor = Color.Black formatMethod.Font = New Font("Courier New", 10) formatMethod.BackColor = Color.Yellow ' Create a lexem that belongs to this format Dim configLex As New ConfigLexem("<%@", "%>", FormatType.Custom, False) configLex.IsBeginRegex = False configLex.IsEndRegex = False configLex.ContinueBlock = ".+" configLex.IsContinueRegex = True configLex.FormatName = "CodeBehind" Me.editControl1.Language.Splits.Add("<%@") Me.editControl1.Language.Splits.Add("%>") ' Add it to the current language's lexems collection Me.editControl1.Language.Lexems.Add(configLex) Me.editControl1.Language.ResetCaches()
Conclusion
I hope you enjoyed about highlight the background of certain tags in HTML or XML dynamically at runtime in Winforms (EditControl).
You can refer to our WinForms Editor feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Editor example to understand how to create and manipulate data. For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!
Reference link: https://help.syncfusion.com/windowsforms/syntax-editor/syntax-highlighting