RichTextBox.SelectionAlignment Eigenschap

Definitie

Hiermee haalt u de uitlijning op of stelt u deze in om toe te passen op de huidige selectie of invoegpositie.

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

Waarde van eigenschap

Een van de HorizontalAlignment waarden.

Kenmerken

Uitzonderingen

De opgegeven waarde is geen van de waarden die in de HorizontalAlignment klasse zijn gedefinieerd.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe u tekst in de RichTextBoxtekst uitlijnt. In dit voorbeeld moet een RichTextBox besturingselement met de naam richTextBox1zijn toegevoegd aan het formulier.

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

Opmerkingen

Als er geen alinea is geselecteerd in het besturingselement, past u met deze eigenschap de uitlijningsinstelling toe op de alinea waarin de invoegpositie wordt weergegeven en op alinea's die zijn gemaakt na de alinea met de instelling van de uitlijningseigenschap. Als er bijvoorbeeld twee alinea's in een RichTextBox besturingselement staan en de invoegpositie zich in de tweede alinea bevindt. Als u de SelectionAlignment eigenschap HorizontalAlignment.Centerinstelt op, wordt de alinea op de invoegpositie gecentreerd in het besturingselement. Als er na de tweede alinea een derde alinea wordt gemaakt, wordt deze ook uitgelijnd op het midden van het besturingselement.

Als er een selectie wordt gemaakt in het besturingselement wanneer de eigenschap is ingesteld, worden alle geselecteerde alinea's uitgelijnd op basis van deze eigenschapsinstelling. U kunt deze eigenschap gebruiken om de alinea's uit te lijnen in een document dat in het RichTextBoxdocument wordt gemaakt. Als u bijvoorbeeld wilt dat alle alinea's in een document worden gecentreerd, kunt u alle alinea's in het besturingselement selecteren en de SelectionAlignment eigenschap instellen op HorizontalAlignment.Center.

Note

SelectionAlignment retourneert SelectionAlignment.Left wanneer de tekstselectie meerdere alinea's met gemengde uitlijning bevat.

Van toepassing op

Zie ook