# RichTextBox class
{: .no_toc }

A **RichTextBox** is a box in which the user types and edits formatted text: characters in several fonts, sizes and colors, paragraphs with their own alignment, indents and bullets, links, and pictures. The program reads and writes the text as plain text or in the Rich Text Format (RTF), and loads it from a file or saves it to one.

![A rich text box with the heading Trip report in a larger bold font, a sentence in which noon is bold and worth the climb is red and in italics, and a list of three bullets: Water, Map and Rain coat](/Reference/Contributed/VBCCR18/RichTextBox/Images/RichTextBox.png){:width="332" height="133"}

```tb check_build check_run arch=win32,win64
RichTextBox1.Text = "Hello world"
RichTextBox1.SelStart = 6
RichTextBox1.SelLength = 5
RichTextBox1.SelBold = True             ' "world" in bold
RichTextBox1.SelColor = vbRed           ' and in red
Debug.Print RichTextBox1.SelText; RichTextBox1.SelBold
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = 11
Debug.Print IsNull(RichTextBox1.SelBold) ' a part is bold, a part is not
' Output:
' worldTrue
' True
```

The control stands in place of the RichTextBox of the Microsoft Rich Textbox control (`RICHTX32.OCX`). It is the rich edit control of Windows in its current version, and holds its text in Unicode. Much of it works as the [**TextBoxW**](/tB/Packages/Contributed/VBCCR18/TextBoxW.md) of the same package does, and the topic pages say where.

Of the [common members](/tB/Packages/Contributed/VBCCR18/Common.md), the control has those under [Name and place](/tB/Packages/Contributed/VBCCR18/Common.md#name-and-place), [Window handles](/tB/Packages/Contributed/VBCCR18/Common.md#window-handles), [Font and visual styles](/tB/Packages/Contributed/VBCCR18/Common.md#font-and-visual-styles), [Mouse](/tB/Packages/Contributed/VBCCR18/Common.md#mouse), [Keyboard and focus](/tB/Packages/Contributed/VBCCR18/Common.md#keyboard-and-focus), [Dragging the control](/tB/Packages/Contributed/VBCCR18/Common.md#dragging-the-control), [OLE drag and drop](/tB/Packages/Contributed/VBCCR18/Common.md#ole-drag-and-drop) and [Right-to-left](/tB/Packages/Contributed/VBCCR18/Common.md#right-to-left) but **RightToLeftLayout**. Its [**OLEDropMode**](/tB/Packages/Contributed/VBCCR18/RichTextBox/DragAndDrop.md#oledropmode) can refuse a value that the common one takes, and is on the page [Drag and Drop](/tB/Packages/Contributed/VBCCR18/RichTextBox/DragAndDrop.md).

* TOC
{:toc}

## Topics

The members of the control are on these pages, by what they do:

- [Text and Typing](/tB/Packages/Contributed/VBCCR18/RichTextBox/Text.md) -- the text as plain text and as RTF, what the user may type, password characters and the **Change** event
- [Selection](/tB/Packages/Contributed/VBCCR18/RichTextBox/Selection.md) -- the selected text and its place, the text of a range, and the **SelChange** event
- [Character Formatting](/tB/Packages/Contributed/VBCCR18/RichTextBox/CharacterFormatting.md) -- the font, the size, the color and the effects of the selected characters
- [Paragraph Formatting](/tB/Packages/Contributed/VBCCR18/RichTextBox/ParagraphFormatting.md) -- alignment, indents, bullets and tab stops
- [Links and Protected Text](/tB/Packages/Contributed/VBCCR18/RichTextBox/LinksAndProtection.md) -- links found in the text or set by the program, and text the user cannot change
- [Finding Text](/tB/Packages/Contributed/VBCCR18/RichTextBox/Finding.md) -- finding a string, and moving the selection over a set of characters
- [Clipboard and Undo](/tB/Packages/Contributed/VBCCR18/RichTextBox/ClipboardAndUndo.md) -- cutting, copying and pasting, and taking changes back and putting them back
- [Lines, Scrolling and Zoom](/tB/Packages/Contributed/VBCCR18/RichTextBox/LinesAndView.md) -- the lines of the text, the scroll bars, the margins and the zoom
- [Loading and Saving](/tB/Packages/Contributed/VBCCR18/RichTextBox/Files.md) -- reading the text from a file and writing it to one
- [Printing](/tB/Packages/Contributed/VBCCR18/RichTextBox/Printing.md) -- the text or the selection on a printer or another device
- [OLE Objects and Pictures](/tB/Packages/Contributed/VBCCR18/RichTextBox/OLEObjects.md) -- pictures and other objects inside the text
- [Shortcut Menus](/tB/Packages/Contributed/VBCCR18/RichTextBox/ShortcutMenu.md) -- the menu that a right click opens
- [Drag and Drop](/tB/Packages/Contributed/VBCCR18/RichTextBox/DragAndDrop.md) -- dragging text out of the box and into it, and dropping files

## RTF and plain text

The box holds its text in paragraphs. [**Text**](/tB/Packages/Contributed/VBCCR18/RichTextBox/Text.md#text) returns the characters alone, and [**TextRTF**](/tB/Packages/Contributed/VBCCR18/RichTextBox/Text.md#textrtf) the same text with its formatting, as a document in the Rich Text Format, a string that starts with `{\rtf1`. The control's default member is **TextRTF**, so `RichTextBox1` alone in an expression is the RTF.

```tb check_build check_run arch=win32,win64
RichTextBox1.TextRTF = "{\rtf1 plain and \b bold\b0  text}"
Debug.Print RichTextBox1.Text
RichTextBox1.SelStart = 10
RichTextBox1.SelLength = 4
Debug.Print RichTextBox1.SelText; RichTextBox1.SelBold
Debug.Print Left$(RichTextBox1, 6)
' Output:
' plain and bold text
' boldTrue
' {\rtf1
```

The properties whose names start with `Sel` read and change the selection, or the text typed next at the insertion point when nothing is selected. Each of them that describes a format is a **Variant**, and returns **Null** while the selection holds more than one value of it.

Properties
----------

### BackColor
{: .no_toc }

The color behind the text. **OLE_COLOR**. Default: **vbWindowBackground**. Text can have a background color of its own, [**SelBkColor**](/tB/Packages/Contributed/VBCCR18/RichTextBox/CharacterFormatting.md#selbkcolor), in front of it. The border that the control draws with visual styles takes the same color.

### BorderStyle
{: .no_toc }

Whether the control has a border. **Integer**: 0 for none or 1 for a border (the default), which is the border of a text box in the visual style of Windows while [**VisualStyles**](/tB/Packages/Contributed/VBCCR18/Common.md#visualstyles) is **True**.

Another value raises run-time error 380.

## See Also

- [Common members](/tB/Packages/Contributed/VBCCR18/Common.md) -- the members this control shares with the package's other controls
- [TextBoxW](/tB/Packages/Contributed/VBCCR18/TextBoxW.md) control -- the text box of the same package, for text without formatting
