RichTextBox.SelectionAlignment Propiedad

Definición

Obtiene o establece la alineación que se aplicará a la selección o al punto de inserción actual.

public:
 property System::Windows::Forms::HorizontalAlignment SelectionAlignment { System::Windows::Forms::HorizontalAlignment get(); void set(System::Windows::Forms::HorizontalAlignment value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.HorizontalAlignment SelectionAlignment { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionAlignment : System.Windows.Forms.HorizontalAlignment with get, set
Public Property SelectionAlignment As HorizontalAlignment

Valor de propiedad

HorizontalAlignment

Uno de los valores de HorizontalAlignment.

Atributos

Excepciones

El valor especificado no es un valor definido en la clase HorizontalAlignment.

Ejemplos

En el ejemplo de código siguiente se muestra cómo alinear texto dentro de RichTextBox. En este ejemplo se requiere que se haya agregado un RichTextBox control, denominado richTextBox1, al formulario.

private:
   void WriteCenteredTextToRichTextBox()
   {
      // Clear all text from the RichTextBox;
      richTextBox1->Clear();

      // Set the foreground color of the text.
      richTextBox1->ForeColor = Color::Red;

      // Set the alignment of the text that follows.
      richTextBox1->SelectionAlignment = HorizontalAlignment::Center;

      // Set the font for the text.
      richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Lucinda Console",12 );

      // Set the text within the control.
      richTextBox1->SelectedText = "This text is centered using the SelectionAlignment property.\n";
   }
private void WriteCenteredTextToRichTextBox()
{
   // Clear all text from the RichTextBox;
   richTextBox1.Clear();
   // Set the foreground color of the text.
   richTextBox1.ForeColor = Color.Red;
   // Set the alignment of the text that follows.
   richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
   // Set the font for the text.
   richTextBox1.SelectionFont = new Font("Lucinda Console", 12);
   // Set the text within the control.
   richTextBox1.SelectedText = "This text is centered using the SelectionAlignment property.\n";
}
Private Sub WriteCenteredTextToRichTextBox()
   ' Clear all text from the RichTextBox;
   richTextBox1.Clear()
   ' Set the foreground color of the text.
   richTextBox1.SelectionColor = Color.Red
   ' Set the alignment of the text that follows.
   richTextBox1.SelectionAlignment = HorizontalAlignment.Center
   ' Set the font for the text.
   richTextBox1.SelectionFont = new Font("Lucinda Console", 12)
   ' Set the text within the control.
   richTextBox1.SelectedText = "This text is centered using the SelectionAlignment property."

End Sub

Comentarios

Si no se selecciona ningún párrafo en el control , al establecer esta propiedad se aplica la configuración de alineación al párrafo en el que aparece el punto de inserción, así como a los párrafos creados después del párrafo que tiene el valor de la propiedad de alineación. Por ejemplo, si hay dos párrafos en un RichTextBox control y el punto de inserción se encuentra dentro del segundo párrafo. Si establece la SelectionAlignment propiedad HorizontalAlignment.Centeren , el párrafo en el punto de inserción se centrará dentro del control . Si se crea un tercer párrafo después del segundo párrafo, también se alinea con el centro del control.

Si se realiza una selección dentro del control cuando se establece la propiedad, todos los párrafos seleccionados se alinean en función de esta configuración de propiedad. Puede usar esta propiedad para alinear los párrafos de un documento que se va a crear en .RichTextBox Por ejemplo, si desea que todos los párrafos de un documento estén centrados, puede seleccionar todos los párrafos del control y establecer la SelectionAlignment propiedad HorizontalAlignment.Centeren .

Nota

SelectionAlignment devuelve SelectionAlignment.Left cuando la selección de texto contiene varios párrafos con alineación mixta.

Se aplica a

Consulte también