RichTextBox.SelectionLength Propiedad

Definición

Obtiene o establece el número de caracteres seleccionados en el control.

public:
 virtual property int SelectionLength { int get(); void set(int value); };
[System.ComponentModel.Browsable(false)]
public override int SelectionLength { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionLength : int with get, set
Public Overrides Property SelectionLength As Integer

Valor de propiedad

Número de caracteres seleccionados en el cuadro de texto.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la SelectionLength propiedad para determinar si el texto está seleccionado dentro de RichTextBox. En este ejemplo se requiere que se haya agregado un RichTextBox control denominado richTextBox1, al formulario. El ejemplo también requiere que richTextBox1 contenga texto seleccionado en el control .

private:
   void ModifySelectedText()
   {
      // Determine if text is selected in the control.
      if ( richTextBox1->SelectionLength > 0 )
      {
         // Set the color of the selected text in the control.
         richTextBox1->SelectionColor = Color::Red;

         // Set the font of the selected text to bold and underlined.
         richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",10,static_cast<FontStyle>(FontStyle::Bold | FontStyle::Underline) );

         // Protect the selected text from modification.
         richTextBox1->SelectionProtected = true;
      }
   }
private void ModifySelectedText()
{
   // Determine if text is selected in the control.
   if (richTextBox1.SelectionLength > 0)
   {
      // Set the color of the selected text in the control.
      richTextBox1.SelectionColor = Color.Red;
      // Set the font of the selected text to bold and underlined.
      richTextBox1.SelectionFont = new Font("Arial",10,FontStyle.Bold | FontStyle.Underline);
      // Protect the selected text from modification.
      richTextBox1.SelectionProtected = true;
   }
}
Private Sub ModifySelectedText()
    ' Determine if text is selected in the control.
    If (richTextBox1.SelectionLength > 0) Then
        ' Set the color of the selected text in the control.
        richTextBox1.SelectionColor = Color.Red
        ' Set the font of the selected text to bold and underlined.
        richTextBox1.SelectionFont = New Font("Arial", 10, FontStyle.Bold Or FontStyle.Underline)
        ' Protect the selected text from modification.
        richTextBox1.SelectionProtected = True
    End If
End Sub

Comentarios

Puede usar esta propiedad para determinar si hay caracteres seleccionados actualmente en el control de cuadro de texto antes de realizar operaciones en el texto seleccionado. También puede usar esta propiedad para determinar el número total de caracteres (incluidos los espacios) que se seleccionan al realizar tareas de un solo carácter en un for bucle.

Se aplica a

Consulte también