--- title: "TextBox Overview" ms.date: "03/30/2017" helpviewer_keywords: - "controls [WPF], TextBox" - "TextBox control [WPF], about TextBox control" ms.assetid: 1ba6dc5b-11a7-4247-9213-36c6729ee35f --- # TextBox Overview The class enables you to display or edit unformatted text. A common use of a is editing unformatted text in a form. For example, a form asking for the user's name, phone number, etc would use controls for text input. 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 input text but the two controls are used for different scenarios. A requires less system resources then a so it is ideal when only plain text needs to be edited (i.e., usage in a form). A is a better choice when it is necessary for the user to edit formatted text, images, tables, or other supported content. For example, editing a document, article, or blog that requires formatting, images, etc is best accomplished using a . The table below summarizes the primary 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 (see [RichTextBox Overview](richtextbox-overview.md))|Yes (see [RichTextBox Overview](richtextbox-overview.md))| > [!NOTE] > Although does not support formatting related editing commands like (Ctr+B), many basic commands are supported by both controls such as . See for more information. Features supported by are covered in the sections below. For more information about , see [RichTextBox Overview](richtextbox-overview.md). ### Real-time Spellchecking You can enable real-time spellchecking 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 picture 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 behavior. See [Use a Custom Context Menu with a TextBox](how-to-use-a-custom-context-menu-with-a-textbox.md) for more information. ## Creating TextBoxes A can be a single line in height or comprise multiple lines. A single line is best for inputting small amounts of plain text (i.e. "Name", "Phone Number", etc. in a form). The following example shows how to create a single line . [!code-xaml[TextBoxMiscSnippets_snip#BasicTextBoxExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/TextBoxMiscSnippets_snip/csharp/basictextboxexample.xaml#basictextboxexamplewholepage)] You can also create a that allows the user to enter multiple lines of text. For example, if your form asked for a biographical sketch of the user, you would want to use a that supports multiple lines of text. The following example shows how to use [!INCLUDE[TLA#tla_xaml](../../../includes/tlasharptla-xaml-md.md)] to define a control that automatically expands to accommodate multiple lines of text. [!code-xaml[TextBox_MiscCode#_MultilineTextBoxXAML](~/samples/snippets/csharp/VS_Snippets_Wpf/TextBox_MiscCode/CSharp/Window1.xaml#_multilinetextboxxaml)] Setting the attribute to `Wrap` causes text to wrap to a new line when the edge of the control is reached, automatically expanding the control to include room for a new line, if necessary. Setting the attribute to `true` causes a new line to be inserted when the RETURN key is pressed, once again automatically expanding the to include room for a new line, if necessary. The attribute adds a scroll bar to the , so that the contents of the can be scrolled through if the expands beyond the size of the frame or window that encloses it. For more information on different tasks associated with using a , see [How-to Topics](textbox-how-to-topics.md). ## 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. ## See also - [How-to Topics](textbox-how-to-topics.md) - [RichTextBox Overview](richtextbox-overview.md)