WinForms SyntaxEditor Overview

The RadSyntaxEditor control works with the underlying document with the help of taggers. Taggers are used to identify spans of text and assign them a specific tag if they match a specific condition. The identification process occurs in the GetTags method which can be overridden in a custom tagger.

The matched tags are then processed by the UI layers which color the text or draw additional elements on screen.

Telerik UI for WinForms Ninja image

The Taggers is part of Telerik UI for WinForms, a professional grade UI library with 160+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.

RadSyntaxEditor with a registered CSharpTagger

WinForms RadSyntaxEditor with a registered CSharpTagger

Predefined Taggers

RadSyntaxEditor comes with a number of predefined taggers and folding taggers:

  • CSharpTagger: A tagger responsible for syntax highlighting in the C# programming language.
  • VisualBasicTagger: A tagger responsible for syntax highlighting in the Visual Basic programming language.
  • JavaScriptTagger: A tagger responsible for syntax highlighting in the JavaScript programming language.
  • XmlTagger: A tagger responsible for syntax highlighting in the XML markup.
  • SqlTagger: A tagger responsible for syntax highlighting in the T-SQL (Transact-SQL) programming language.
  • JsonTagger: A tagger responsible for syntax highlighting in the JSON format.
  • BracketFoldingTagger: A tagger responsible for creating collapsible (folding) regions in the code. Can be used for the JavaScript language.
  • SquareBracketFoldingTagger: A tagger responsible for creating collapsible (folding) regions in the code. Can be used for the JSON format.
  • CSharpFoldingTagger: A tagger responsible for creating folding regions in C# code.
  • VisualBasicFoldingTagger: A tagger responsible for creating folding regions in Visual Basic code.
  • XmlFoldingTagger: A tagger responsible for creating collapsible (folding) regions in XML, XAML, and HTML code documents.
  • JavaScriptFoldingTagger: A tagger class responsible for creating collapsible (folding) regions in JavaScript code documents.
  • TextSearchHighlightTagger: A tagger that prepares a collection of TextHighlightTag for all occurrences of a given search word. The class exposes a UpdateSearchWord method used to determine the word that will be highlighted.
  • TextSearchUnderlineTagger: A tagger that prepares a collection of UnderlineTag for all occurrences of a given search word. The class exposes a UpdateSearchWord method used to determine the word that will be underlined.
  • LineHighlightTagger: A tagger that prepares a collection of TextHighlightTags for a collection of lines. The class exposes a HighlightLines method taking an IEnumerable and is used to determine the lines that will be highlighted. The tagger also provides a HighlightMode property of type LineHighlightMode which has the following possible values:
    • TextOnly: Highlights only the text portion of the line. This is the default value.
    • LineStartToTextEnd: Highlights from the beginning of the line to the end of the text portion of the line.

Register a Tagger

To be able to use these taggers in the RadSyntaxEditor control, you first need to register them in its TaggersRegistry. This registry keeps track of all the registered taggers. Through the IsTaggerRegistered method you can check whether a specific tagger is already registered.

Registering taggers

            CSharpTagger currentLanguageTagger = new Telerik.WinForms.Controls.SyntaxEditor.Tagging.Taggers.CSharpTagger(this.radSyntaxEditor1.SyntaxEditorElement);
            this.radSyntaxEditor1.TaggersRegistry.RegisterTagger(currentLanguageTagger);

            CSharpFoldingTagger foldingTagger = new Telerik.WinForms.Controls.SyntaxEditor.Taggers.CSharpFoldingTagger(this.radSyntaxEditor1.SyntaxEditorElement);
            foldingTagger.FoldingRegionDefinitions.Add(new FoldingRegionDefinition("#if", "#endif"));


Dim currentLanguageTagger As CSharpTagger = New Telerik.WinForms.Controls.SyntaxEditor.Taggers.CSharpTagger(Me.RadSyntaxEditor1.SyntaxEditorElement)
Me.RadSyntaxEditor1.TaggersRegistry.RegisterTagger(currentLanguageTagger)
Dim foldingTagger As CSharpFoldingTagger = New Telerik.WinForms.Controls.SyntaxEditor.Taggers.CSharpFoldingTagger(Me.RadSyntaxEditor1.SyntaxEditorElement)
foldingTagger.FoldingRegionDefinitions.Add(New FoldingRegionDefinition("#if", "#endif"))
RadSyntaxEditor1.TaggersRegistry.RegisterTagger(foldingTagger)


As of R2 2021 RadSyntaxEditor offers ShouldTaggersProcessEntireLines property that indicates whether the entire line should be processed by the taggers.

See Also

In this article