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)
Visual Basic (Declaration)
<BrowsableAttribute(False)> _
Public Property SelectionColor As Color
Dim instance As RichTextBox
Dim value As Color
value = instance.SelectionColor
instance.SelectionColor = value
[BrowsableAttribute(false)]
public Color SelectionColor { get; set; }
[BrowsableAttribute(false)]
public:
property Color SelectionColor {
Color get ();
void set (Color value);
}
public function get SelectionColor () : Color
public function set SelectionColor (value : Color)
Property Value
Type:
System.Drawing..::.ColorA 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 Sub ChangeMySelectionColor()
Dim colorDialog1 As 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) _
And Not(colorDialog1.Color.Equals(richTextBox1.SelectionColor)) Then
' Change the selection color to the user specified color.
richTextBox1.SelectionColor = colorDialog1.Color
End If
End Sub
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;
}
}
public:
void ChangeMySelectionColor()
{
ColorDialog^ colorDialog1 = gcnew 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;
}
}
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Reference