New to Telerik UI for WinFormsStart a free 30-day trial

Selection

Updated over 6 months ago

The RadSyntaxEditor control supports not only selection via the UI but also exposes API to work with the selection programmatically. In addition, the selection can be controlled via the keyboard by a number of key combinations. You can also disable selection in the control if your business scenario demands it.

UI Selection

The user is able to select the content inside RadSyntaxEditor in the same way as in Visual Studio. This is done by clicking on the desired position and dragging to the desired end of the selection.

Figure 1: RadSyntaxEditor with selected text

WinForms RadSyntaxEditor with selected text

The UI selection is enabled by default. To enable or disable it use the IsSelectionEnabled property

Enable/Disable selection

C#
this.radSyntaxEditor1.IsSelectionEnabled = true;

Keyboard Combinations

Users can also select text by using their keyboard. Here's a list of the supported key combinations.

Table 1: Hotkeys supported by the RadSyntaxEditor and their actions

HotkeysAction
Shift + Right arrowExtends selection one position forward.
Shift + Left arrowExtends selection one position backward.
Shift + Up arrowExtends selection to the same position on the previous line.
Shift + Down arrowExtends selection to the same position on the next line.
Shift + HomeExtends selection to the start of the current line.
Shift + EndExtends selection to the end of the current line.
Ctrl + Shift + Left arrowExtends selection to the current word start position.
Ctrl + Shift + Right arrowExtends selection to the current word end position.
Ctrl + ASelects the entire document.

Customize the Selection

You can modify the appearance of the selection in the control through the SelectionFill and SelectionStroke properties of RadSyntaxEditor.

Customize the appearance of the selection

C#
 this.radSyntaxEditor1.SyntaxEditorElement.SelectionFill = new SolidBrush(Color.FromArgb(95, Color.Red));
 this.radSyntaxEditor1.SyntaxEditorElement.SelectionStroke = new SolidBrush(Color.DarkRed);

Figure 2: RadSyntaxEditor with custom selection color

WinForms RadSyntaxEditor with custom selection color

Programmatic Selection

Through the control's Selection property, you can programmatically manipulate the selection and get additional details for the selected span(s). The following example demonstrates how you can get the entire selection as a string through the GetSelectedText method.

C#
string selectedText = this.radSyntaxEditor1.SyntaxEditorElement.Selection.GetSelectedText();

See Also