New to Telerik UI for WinForms? Download free 30-day trial

Getting Started with WinForms SyntaxEditor

This tutorial will walk you through the creation of a sample application that contains a RadSyntaxEditor control.

Defining RadSyntaxEditor

To start using the control you only need to add a RadSyntaxEditor to the form either at design time by dragging it from the Toolbox and dropping it into the form or at run time via code.

Adding a RadSyntaxEditor at run time

RadSyntaxEditor radSyntaxEditor1 = new RadSyntaxEditor();

Dim radSyntaxEditor1 As RadSyntaxEditor = New RadSyntaxEditor()

Figure 1: Empty RadSyntaxEditor

WinForms RadSyntaxEditor Empty

Opening a File

To load a file in the RadSyntaxEditor you need to use its Document property.

public RadForm1()

            using (StreamReader reader = new StreamReader("../../CS_File.txt"))
               this.radSyntaxEditor1.Document = new TextDocument(reader);

Public Sub New()

    Using Reader As StreamReader = New StreamReader("../../CS_File.txt")
        Me.RadSyntaxEditor1.Document = New TextDocument(Reader)
    End Using
End Sub

Figure 2: RadSyntaxEditor with a loaded C# file

WinForms RadSyntaxEditor with a Loaded CSharp File

Enable Syntax Highlighting

Once you have loaded the code, you need to register an appropriate tagger to enable syntax highlighting for the particular language.

CSharpTagger cSharptagger = new CSharpTagger(this.radSyntaxEditor1.SyntaxEditorElement);

Dim CSharptagger As CSharpTagger = New CSharpTagger(Me.radSyntaxEditor1.SyntaxEditorElement)

Figure 3: RadSyntaxEditor with C# code highlighting

WinForms RadSyntaxEditor with CSharp Code Highlighting

Telerik UI for WinForms Learning Resources

In this article