RichTextBox.SelectionColor 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置当前文本选择或插入点的文本颜色。
public:
property System::Drawing::Color SelectionColor { System::Drawing::Color get(); void set(System::Drawing::Color value); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Color SelectionColor { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionColor : System.Drawing.Color with get, set
Public Property SelectionColor As Color
属性值
一个 Color 表示应用于当前文本选择或插入点后输入的文本的颜色。
- 属性
示例
下面的代码示例向用户显示一个 ColorDialog 颜色,以指定在控件中的 RichTextBox 当前插入点之后输入的当前文本选择或文本的颜色。 此示例要求将示例中定义的方法添加到包含
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;
}
}
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 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
注解
如果当前文本选择指定了多个颜色,则此属性返回 Color.Empty。 如果未选择任何文本,则此属性中指定的文本颜色将应用于当前插入点以及插入点后键入控件的所有文本。 文本颜色设置将应用于属性更改为其他颜色,或直到插入点移动到控件中的其他节。
如果在控件中选择文本,则所选文本和文本选择后输入的任何文本都将应用此属性的值。 可以使用此属性更改文本的颜色 RichTextBox。
若要使控件中的文本加粗,请使用 SelectionFont 属性分配指定加粗字体样式的新字体。