--- title: "RichTextBox Overview" description: Learn how the Windows Presentation Foundation RichTextBox control lets users display or edit content like text, images, and tables. See XAML and C# examples. ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "controls [WPF], RichTextBox" - "RichTextBox control [WPF], about RichTextBox control" ms.assetid: c94548b2-c1e9-4b62-b10c-dd8740eb23d8 --- # RichTextBox Overview The control enables you to display or edit flow content including paragraphs, images, tables, and more. This topic introduces the class and provides examples of how to use it in both [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)] and C#. ## TextBox or RichTextBox? Both and allow users to edit text, however, the two controls are used in different scenarios. A is a better choice when it is necessary for the user to edit formatted text, images, tables, or other rich content. For example, editing a document, article, or blog that requires formatting, images, etc is best accomplished using a . A requires less system resources then a and it is ideal when only plain text needs to be edited (i.e. usage in forms). See [TextBox Overview](textbox-overview.md) for more information on . The table below summarizes the main features of and . |Control|Real-time Spellchecking|Context Menu|Formatting commands like (Ctr+B)| content like images, paragraphs, tables, etc.| |-------------|------------------------------|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ||Yes|Yes|No|No.| ||Yes|Yes|Yes|Yes| > [!NOTE] > Although does not support formatting related commands like (Ctr+B), many basic commands are supported by both controls such as . The features from the table above are covered in more detail later. ## Creating a RichTextBox The code below shows how to create a that a user can edit rich content in. [!code-xaml[RichTextBoxMiscSnippets_snip#BasicRichTextBoxExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/RichTextBoxMiscSnippets_snip/CSharp/BasicRichTextBoxExample.xaml#basicrichtextboxexamplewholepage)] Specifically, the content edited in a is flow content. Flow content can contain many types of elements including formatted text, images, lists, and tables. See [Flow Document Overview](../advanced/flow-document-overview.md) for in depth information on flow documents. In order to contain flow content, a hosts a object which in turn contains the editable content. To demonstrate flow content in a , the following code shows how to create a with a paragraph and some bolded text. [!code-xaml[RichTextBoxMiscSnippets_snip#RichTextBoxWithContentExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/RichTextBoxMiscSnippets_snip/CSharp/RichTextBoxWithContentExample.xaml#richtextboxwithcontentexamplewholepage)] [!code-csharp[RichTextBoxMiscSnippets_procedural_snip#BasicRichTextBoxWithContentCodeOnlyExample](~/samples/snippets/csharp/VS_Snippets_Wpf/RichTextBoxMiscSnippets_procedural_snip/CSharp/BasicRichTextBoxWithContentExample.cs#basicrichtextboxwithcontentcodeonlyexample)] [!code-vb[RichTextBoxMiscSnippets_procedural_snip#BasicRichTextBoxWithContentCodeOnlyExample](~/samples/snippets/visualbasic/VS_Snippets_Wpf/RichTextBoxMiscSnippets_procedural_snip/visualbasic/basicrichtextboxwithcontentexample.vb#basicrichtextboxwithcontentcodeonlyexample)] The following illustration shows how this sample renders. ![RichTextBox with content](./media/editing-richtextbox-with-content.png "Editing_RichTextBox_with_Content") Elements like and determine how the content inside a appears. As a user edits content, they change this flow content. To learn more about the features of flow content and how to work with it, see [Flow Document Overview](../advanced/flow-document-overview.md). > [!NOTE] > Flow content inside a does not behave exactly like flow content contained in other controls. For example, there are no columns in a and hence no automatic resizing behavior. Also, built in features like search, viewing mode, page navigation, and zoom are not available within a . ## Real-time Spell Checking You can enable real-time spell checking in a or . When spellchecking is turned on, a red line appears underneath any misspelled words (see picture below). ![Textbox with spell-checking](./media/editing-textbox-with-spellchecking.png "Editing_TextBox_with_Spellchecking") See [Enable Spell Checking in a Text Editing Control](how-to-enable-spell-checking-in-a-text-editing-control.md) to learn how to enable spellchecking. ## Context Menu By default, both and have a context menu that appears when a user right-clicks inside the control. The context menu allows the user to cut, copy, or paste (see illustration below). ![TextBox with context menu](./media/editing-textbox-with-context-menu.png "Editing_TextBox_with_Context_Menu") You can create your own custom context menu to override the default one. See [Position a Custom Context Menu in a RichTextBox](how-to-position-a-custom-context-menu-in-a-richtextbox.md) for more information. ## Editing Commands Editing commands enable users to format editable content inside a . Besides basic editing commands, includes formatting commands that does not support. For example, when editing in a , a user could press Ctr+B to toggle bold text formatting. See for a complete list of commands available. In addition to using keyboard shortcuts, you can hook commands up to other controls like buttons. The following example shows how to create a simple tool bar containing buttons that the user can use to change text formatting. [!code-xaml[RichTextBox_InputPanel_snip#RichTextBoxWithToolBarExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/RichTextBox_InputPanel_snip/CS/Window1.xaml#richtextboxwithtoolbarexamplewholepage)] The following illustration shows how this sample displays. ![RichTextBox with ToolBar](./media/editing-richtextbox-with-toobar.gif "Editing_RichTextBox_with_TooBar") ## Detect when Content Changes Usually the event should be used to detect whenever the text in a or changes rather then as you might expect. See [Detect When Text in a TextBox Has Changed](how-to-detect-when-text-in-a-textbox-has-changed.md) for an example. ## Save, Load, and Print RichTextBox Content The following example shows how to save content of a to a file, load that content back into the , and print the contents. Below is the markup for the example. [!code-xaml[RichTextBoxMiscSnippets_snip#SaveLoadPrintRTBExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/RichTextBoxMiscSnippets_snip/CSharp/SaveLoadPrintRTB.xaml#saveloadprintrtbexamplewholepage)] Below is the code behind for the example. [!code-csharp[RichTextBoxMiscSnippets_snip#SaveLoadPrintRTBCodeExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/RichTextBoxMiscSnippets_snip/CSharp/SaveLoadPrintRTB.xaml.cs#saveloadprintrtbcodeexamplewholepage)] [!code-vb[RichTextBoxMiscSnippets_snip#SaveLoadPrintRTBCodeExampleWholePage](~/samples/snippets/visualbasic/VS_Snippets_Wpf/RichTextBoxMiscSnippets_snip/VisualBasic/SaveLoadPrintRTB.xaml.vb#saveloadprintrtbcodeexamplewholepage)] ## See also - [How-to Topics](richtextbox-how-to-topics.md) - [TextBox Overview](textbox-overview.md)