RichTextBox.SelectionAlignment Egenskap

Definition

Hämtar eller ställer in justeringen som ska tillämpas på den aktuella markeringen eller insättningspunkten.

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

Egenskapsvärde

Ett av HorizontalAlignment värdena.

Attribut

Undantag

Det angivna värdet är inte ett av de värden som definierats i HorizontalAlignment klassen.

Exempel

Följande kodexempel visar hur du justerar text i RichTextBox. Det här exemplet kräver att en RichTextBox kontroll med namnet richTextBox1, har lagts till i formuläret.

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

Kommentarer

Om inget stycke har markerats i kontrollen tillämpas justeringsinställningen på det stycke där insättningspunkten visas samt på stycken som skapats efter stycket som har inställningen justeringsegenskap. Om det till exempel finns två stycken i en RichTextBox kontroll och insättningspunkten finns i det andra stycket. Om du anger SelectionAlignment egenskapen till HorizontalAlignment.Centercentreras stycket vid insättningspunkten i kontrollen. Om ett tredje stycke skapas efter det andra stycket justeras det också mot mitten av kontrollen.

Om en markering görs i kontrollen när egenskapen har angetts justeras alla markerade stycken baserat på den här egenskapsinställningen. Du kan använda den här egenskapen för att justera styckena i ett dokument som skapas i RichTextBox. Om du till exempel vill att alla stycken i ett dokument ska centreras kan du välja alla stycken i kontrollen och ange SelectionAlignment egenskapen till HorizontalAlignment.Center.

Note

SelectionAlignment returnerar SelectionAlignment.Left när textmarkeringen innehåller flera stycken med blandad justering.

Gäller för

Se även