Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/change-selection-in-a-richtextbox-programmatically.md
Andy (Steve) De George be103da07e Replace various WPF include files with content (#1335)
* net-current-v30plus-md.md

* net-current-v40plus-md.md

* tla2sharptla-ui-md.md

* tla2sharptla-uiautomation-md.md

* tla2sharptla-winclient-md.md

* tla2sharptla-xaml-md.md

* tlasharptla-ui-md.md

* tlasharptla-uiautomation-md.md

* tlasharptla-winclient-md.md

* tlasharptla-xaml-md.md

* fix warnings
2022-03-16 12:14:11 -04:00

1.9 KiB

title, ms.date, ms.custom, description, dev_langs, helpviewer_keywords, ms.assetid
title ms.date ms.custom description dev_langs helpviewer_keywords ms.assetid
Change Selection in a RichTextBox Programmatically 03/30/2017 devdivchpfy22 Learn how to change selection in a RichTextBox programmatically.
csharp
vb
changing selections in a text box [WPF]
changing selections in a RichTextBox [WPF]
f1213205-1ad7-4cd2-b115-460173cc5aa3

Change Selection in a RichTextBox Programmatically

This example shows how to programmatically change the current selection in a xref:System.Windows.Controls.RichTextBox. This selection is the same as if the user had selected the content by using the user interface.

Code example for a RichTextBox control

The following Extensible Application Markup Language (XAML) code describes a named xref:System.Windows.Controls.RichTextBox control with simple content.

[!code-xamlRichTextBoxMiscSnippets_snip#ChangeSelectionProgrammaticalyExampleWholePage]

Code example to select text from a RichTextBox

The following code programmatically selects some arbitrary text when the user clicks inside the xref:System.Windows.Controls.RichTextBox.

[!code-csharpRichTextBoxMiscSnippets_snip#ChangeSelectionProgrammaticalyCodeExampleWholePage] [!code-vbRichTextBoxMiscSnippets_snip#ChangeSelectionProgrammaticalyCodeExampleWholePage]

See also