$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
RichTextBox WinForms Control
Edit rich text content with text formatting options, mail-merge, table, and floating objects, etc.
Home > WinForms UI Controls > User Manual > Selection in RichTextBox in C#

Selection of RichTextBox in C#.NET

KetticRichTextBox control for Windows Forms is capable of selection for the users. It supports both user interface selection and the selection in C# code in .NET template projects. The user interface selection, or UI selection, allows the users to select the content of KetticRichTextBox in a similar way of Microsoft Word and the selection in C#, or selection programmatically, allows the developers perform the selection in their .NET projects.

UI Selection of KetticRichTextBox

The user interface selection of KetticRichTextBox resembles the selection of Microsoft Word. To perform the UI selection in KetticRichTextBox control, we can click on the start position and then drag to the end position desired to select the content. This control also supports multiple ranges selection, which can be achieved through pressing the Ctrl key while we select the contents of different ranges.

C# Select Content of KetticRichTextBox

KetticRichTextBox control allows the developers to select the content in C#.NET template project. The programmatic selection will be applied to select the found string when there is a Find functionality in the KetticRichTextBox.
To implement the selection in C# code, we shall use the DocumentSelection C# class, whose instance is associated with the KetticDocument of KetticRichTextBox and allows the developers to assign the starts/ends, as well as ranges of the selection. KetticDocument contains the Selection property for the users to manipulate the selection. Alternatively, you can create an instance of the DocumentSelection C# class to customize the selection.
The C# code below shows how to select the current text in the document in .NET project.

DocumentPosition startPosition = this.ketticRichTextBox1.Document.CaretPosition;
DocumentPosition endPosition = new DocumentPosition(startPosition);
startPosition.MoveToCurrentTextStart();
endPosition.MoveToCurrentTextEnd();
this.ketticRichTextBox1.Document.Selection.AddSelectionStart(startPosition);
this.ketticRichTextBox1.Document.Selection.AddSelectionEnd(endPosition);

Multiple Ranges Selection of KetticRichTextBox

KetticRichTextBox control provides the methods, AddSelectionStart() and AddSelectionEnd(), for the users to implement multiple ranges selection. Alternatively, it is also possible to select multiple ranges by using the Ranges collection of the KetticDocument. The following C# code sample demonstrates how to select the specific text, Kettic, in the content of document.

DocumentPosition position = new DocumentPosition( this.ketticRichTextBox1.Document );
do
{
string word = position.GetCurrentSpanBox().Text;
if ( word.Contains( "Kettic" ))
{
DocumentPosition wordEndPosition = new DocumentPosition( position );
wordEndPosition.MoveToCurrentWordEnd();
this.ketticRichTextBox1.Document.Selection.AddSelectionStart( position );
this.ketticRichTextBox1.Document.Selection.AddSelectionEnd( wordEndPosition );
}
}
while (position.MoveToNextWordStart());

UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls