Search in RichTextBox for C# Windows Forms
KetticRichTextBox WinForms control allows the users to search contents in the document. This is achieved through using some methods for managing the selection of KetticRichTextBox. When the users combine the Search functionality and selection of document together, they can do a lot of operations to the text of document. By the search functionality, we can highlight text of document, as well as replace words and collocations, etc.
C# Search Text in KetticRichTextBox
The following C# code sample demonstrates how to search a string in the text of document in KetticRichTextBox.
The search functionality allows the users to apply all regular expressions and escape the search string by invoking the C# code below.
In addition, the KetticRichTextBox control allows the users to select text from the search results. This functionality will be performed on the parts of the document that are selected currently. The C# code below is an example shows how to customize the selection.
When the users need to remove the selection, they can call the Clear() method of the DocumentSelection object as the simple C# code snippet as below.
Moreover, KetticRichTextBox control allows the users to extend the search and selection functionality to replace the text of searched results. The following C# code demonstrates how to replace the searched string.
When we add or remove strings to the document, the positions will be changed, so that we may need to create new TextRanges with document positions to tack the changes. The users can enable the second property of the two properties constructor to keep the relative position when the document changes.
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