This documentation is archived and is not being maintained.

RichTextBox.SelectionColor Property

Gets or sets the text color of the current text selection or insertion point.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public Color SelectionColor { get; set; }

Property Value

Type: System.Drawing.Color
A Color that represents the color to apply to the current text selection or to text entered after the insertion point.

If the current text selection has more than one color specified, this property returns Color.Empty. If no text is currently selected, the text color specified in this property is applied to the current insertion point and to all text that is typed into the control after the insertion point. The text color setting applies until the property is changed to a different color or until the insertion point is moved to a different section within the control.

If text is selected within the control, the selected text and any text entered after the text selection will have the value of this property applied to it. You can use this property to change the color of text in the RichTextBox.

To make text bold in the control, use the SelectionFont property to assign a new font that has the bold font style specified.

The following code example displays a ColorDialog to the user to specify a color for the current text selection or text entered after the current insertion point in a RichTextBox control. This example requires that the method defined in the example is added to a Form class that contains a RichTextBox control named richTextBox1.

public void ChangeMySelectionColor()
   ColorDialog colorDialog1 = new ColorDialog();

   // Set the initial color of the dialog to the current text color.
   colorDialog1.Color = richTextBox1.SelectionColor;

   // Determine if the user clicked OK in the dialog and that the color has changed.
   if(colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK && 
      colorDialog1.Color != richTextBox1.SelectionColor)
      // Change the selection color to the user specified color.
      richTextBox1.SelectionColor = colorDialog1.Color;

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.