--- title: "How to: Extract the Text Content from a RichTextBox" description: Learn how to extract the Text Content from a RichTextBox. ms.date: "03/30/2017" ms.custom: devdivchpfy22 dev_langs: - "csharp" - "vb" helpviewer_keywords: - "text content [WPF], extracting" - "RichTextBox control [WPF], extracting text content" - "content [WPF], extracting" - "extracting text content [WPF]" ms.assetid: f13c093f-1a05-45b3-ac8f-c9ea5e4a11c5 --- # How to: Extract the Text Content from a RichTextBox This example shows how to extract the contents of a as plain text. ## Describe a RichTextBox control The following [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)] code describes a named control with simple content. [!code-xaml[RichTextBoxSnippets#_RTB_XAML](~/samples/snippets/csharp/VS_Snippets_Wpf/RichTextBoxSnippets/CSharp/Window1.xaml#_rtb_xaml)] ## Code example with RichTextBox as an argument The following code implements a method that takes a as an argument, and returns a string representing the plain text contents of the . The method creates a new from the contents of the , using the and to indicate the range of the contents to extract. and properties each return a , and are accessible on the underlying FlowDocument that represents the contents of the . provides a Text property, which returns the plain text portions of the as a string. [!code-csharp[RichTextBoxSnippets#_RTB_StringFrom](~/samples/snippets/csharp/VS_Snippets_Wpf/RichTextBoxSnippets/CSharp/Window1.xaml.cs#_rtb_stringfrom)] [!code-vb[RichTextBoxSnippets#_RTB_StringFrom](~/samples/snippets/visualbasic/VS_Snippets_Wpf/RichTextBoxSnippets/visualbasic/window1.xaml.vb#_rtb_stringfrom)] ## See also - [RichTextBox Overview](richtextbox-overview.md) - [TextBox Overview](textbox-overview.md)