RichTextBox.SelectionColor Propiedad

Definición

Obtiene o establece el color del texto seleccionado o el color del texto en el punto de inserción actual.

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

Valor de propiedad

Color que representa el color que se aplicará al texto seleccionado actualmente o al texto que se escriba a continuación del punto de inserción.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra un objeto ColorDialog al usuario para especificar un color para la selección de texto actual o el texto especificado después del punto de inserción actual en un RichTextBox control . En este ejemplo se requiere que el método definido en el ejemplo se agregue a una Form clase que contenga un RichTextBox control denominado richTextBox1.

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

Comentarios

Si la selección de texto actual tiene más de un color especificado, esta propiedad devuelve Color.Empty. Si no hay texto seleccionado actualmente, el color de texto especificado en esta propiedad se aplica al punto de inserción actual y a todo el texto que se escribe en el control después del punto de inserción. La configuración de color de texto se aplica hasta que la propiedad cambia a un color diferente o hasta que el punto de inserción se mueve a una sección diferente dentro del control.

Si se selecciona texto dentro del control, el texto seleccionado y cualquier texto escrito después de la selección de texto tendrá aplicado el valor de esta propiedad. Puede usar esta propiedad para cambiar el color del texto en RichTextBox.

Para hacer negrita de texto en el control, utilice la SelectionFont propiedad para asignar una nueva fuente que tenga el estilo de fuente en negrita especificado.

Se aplica a

Consulte también