Share via


RichTextBox Control Overview (Windows Forms)

The Windows Forms RichTextBox control is used for displaying, entering, and manipulating text with formatting. The RichTextBox control does everything the TextBox control does, but it can also display fonts, colors, and links; load text and embedded images from a file; and find specified characters. The RichTextBox control is typically used to provide text manipulation and display features similar to word processing applications such as Microsoft Word. Like the TextBox control, the RichTextBox control can display scroll bars; but unlike the TextBox control, its default setting is to display both horizontal and vertical scrollbars as needed, and it has additional scrollbar settings.

Working with the RichTextBox Control

As with the TextBox control, the text displayed is set by the Text property. The RichTextBox control has numerous properties to format text. For details on these properties, see How to: Set Font Attributes for the Windows Forms RichTextBox Control and How to: Set Indents, Hanging Indents, and Bulleted Paragraphs with the Windows Forms RichTextBox Control. To manipulate files, the LoadFile and SaveFile methods can display and write multiple file formats including plain text, Unicode plain text, and Rich Text Format (RTF). The possible file formats are listed in RichTextBoxStreamType Enumeration. You can use the Find method to find strings of text or specific characters.

You can also use a RichTextBox control for Web-style links by setting the DetectUrls property to true and writing code to handle the LinkClicked event. For more information, see How to: Display Web-Style Links with the Windows Forms RichTextBox Control. You can prevent the user from manipulating some or all of the text in the control by setting the SelectionProtected property to true.

You can undo and redo most edit operations in a RichTextBox control by calling the Undo and Redo methods. The CanRedo method enables you to determine whether the last operation the user has undone can be reapplied to the control.

See Also

Reference

RichTextBox

TextBox Control Overview (Windows Forms)

Other Resources

RichTextBox Control (Windows Forms)