Share via


RichTextBox.SelectionAlignment Propriedade

Definição

Obtém ou define o alinhamento a ser aplicado ao ponto de inserção ou seleção atual.

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 da propriedade

Um dos valores de HorizontalAlignment.

Atributos

Exceções

O valor especificado não é um dos valores definidos na classe HorizontalAlignment.

Exemplos

O exemplo de código a seguir demonstra como alinhar o texto dentro do RichTextBox. Este exemplo requer que um RichTextBox controle, chamado richTextBox1, tenha sido adicionado ao formulário.

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

Comentários

Se nenhum parágrafo for selecionado no controle, definir essa propriedade aplicará a configuração de alinhamento ao parágrafo no qual o ponto de inserção aparece, bem como aos parágrafos criados após o parágrafo que tem a configuração da propriedade alignment. Por exemplo, se houver dois parágrafos em um RichTextBox controle e o ponto de inserção estiver localizado dentro do segundo parágrafo. Se você definir a SelectionAlignment propriedade como HorizontalAlignment.Center, o parágrafo no ponto de inserção será centralizado dentro do controle . Se um terceiro parágrafo for criado após o segundo parágrafo, ele também será alinhado ao centro do controle.

Se uma seleção for feita dentro do controle quando a propriedade for definida, todos os parágrafos selecionados serão alinhados com base nessa configuração de propriedade. Você pode usar essa propriedade para alinhar os parágrafos em um documento que está sendo criado no RichTextBox. Por exemplo, se você quiser que todos os parágrafos em um documento sejam centralizados, poderá selecionar todos os parágrafos no controle e definir a SelectionAlignment propriedade como HorizontalAlignment.Center.

Observação

SelectionAlignment retorna SelectionAlignment.Left quando a seleção de texto contém vários parágrafos com alinhamento misto.

Aplica-se a

Confira também