* 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
2.4 KiB
title, description, ms.date, ms.custom, dev_langs, helpviewer_keywords, ms.assetid
| title | description | ms.date | ms.custom | dev_langs | helpviewer_keywords | ms.assetid | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| How to: Extract the Text Content from a RichTextBox | Learn how to extract the Text Content from a RichTextBox. | 03/30/2017 | devdivchpfy22 |
|
|
f13c093f-1a05-45b3-ac8f-c9ea5e4a11c5 |
How to: Extract the Text Content from a RichTextBox
This example shows how to extract the contents of a xref:System.Windows.Controls.RichTextBox as plain text.
Describe a RichTextBox control
The following Extensible Application Markup Language (XAML) code describes a named xref:System.Windows.Controls.RichTextBox control with simple content.
[!code-xamlRichTextBoxSnippets#_RTB_XAML]
Code example with RichTextBox as an argument
The following code implements a method that takes a xref:System.Windows.Controls.RichTextBox as an argument, and returns a string representing the plain text contents of the xref:System.Windows.Controls.RichTextBox.
The method creates a new xref:System.Windows.Documents.TextRange from the contents of the xref:System.Windows.Controls.RichTextBox, using the xref:System.Windows.Documents.FlowDocument.ContentStart%2A and xref:System.Windows.Documents.FlowDocument.ContentEnd%2A to indicate the range of the contents to extract. xref:System.Windows.Documents.FlowDocument.ContentStart%2A and xref:System.Windows.Documents.FlowDocument.ContentEnd%2A properties each return a xref:System.Windows.Documents.TextPointer, and are accessible on the underlying FlowDocument that represents the contents of the xref:System.Windows.Controls.RichTextBox. xref:System.Windows.Documents.TextRange provides a Text property, which returns the plain text portions of the xref:System.Windows.Documents.TextRange as a string.
[!code-csharpRichTextBoxSnippets#_RTB_StringFrom] [!code-vbRichTextBoxSnippets#_RTB_StringFrom]