RichTextBox.SelectionAlignment Propriedade

Definição

Obtém ou define o alinhamento para se aplicar ao ponto de seleção ou inserçã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 de Propriedade

Um dos HorizontalAlignment valores.

Atributos

Exceções

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

Exemplos

O exemplo de código seguinte demonstra como alinhar texto dentro do RichTextBox. Este exemplo exige que um RichTextBox controlo, 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

Observações

Se não for selecionado nenhum parágrafo no controlo, definir esta propriedade aplica a definição de alinhamento ao parágrafo onde aparece o ponto de inserção, bem como aos parágrafos criados após o parágrafo que tem a definição de propriedade de alinhamento. Por exemplo, se houver dois parágrafos num RichTextBox controlo e o ponto de inserção estiver localizado dentro do segundo parágrafo. Se definires a SelectionAlignment propriedade para HorizontalAlignment.Center, o parágrafo no ponto de inserção ficará centrado dentro do controlo. Se um terceiro parágrafo for criado após o segundo, também está alinhado com o centro do controlo.

Se uma seleção for feita dentro do controlo quando a propriedade é definida, todos os parágrafos selecionados são alinhados com base nesta definição de propriedade. Pode usar esta propriedade para alinhar os parágrafos num documento que está a ser criado no RichTextBoxarquivo . Por exemplo, se quiser que todos os parágrafos de um documento fiquem centrados, pode selecionar todos os parágrafos no controlo e definir a SelectionAlignment propriedade para HorizontalAlignment.Center.

Note

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

Aplica-se a

Ver também