Partager via


RichTextBox.SelectionAlignment Propriété

Définition

Obtient ou définit l’alignement à appliquer au point de sélection ou d’insertion actuel.

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

Valeur de propriété

Une des HorizontalAlignment valeurs.

Attributs

Exceptions

La valeur spécifiée n’est pas l’une des valeurs définies dans la HorizontalAlignment classe.

Exemples

L’exemple de code suivant montre comment aligner le texte dans le RichTextBox. Cet exemple nécessite qu’un RichTextBox contrôle nommé richTextBox1ait été ajouté au formulaire.

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

Remarques

Si aucun paragraphe n’est sélectionné dans le contrôle, la définition de cette propriété applique le paramètre d’alignement au paragraphe dans lequel le point d’insertion apparaît ainsi qu’aux paragraphes créés après le paramètre de propriété d’alignement. Par exemple, s’il existe deux paragraphes dans un RichTextBox contrôle et que le point d’insertion se trouve dans le deuxième paragraphe. Si vous définissez la SelectionAlignment propriété HorizontalAlignment.Centersur , le paragraphe au point d’insertion est centré dans le contrôle. Si un troisième paragraphe est créé après le deuxième paragraphe, il est également aligné au centre du contrôle.

Si une sélection est effectuée dans le contrôle lorsque la propriété est définie, tous les paragraphes sélectionnés sont alignés en fonction de ce paramètre de propriété. Vous pouvez utiliser cette propriété pour aligner les paragraphes d’un document en cours de création dans le RichTextBox. Par exemple, si vous souhaitez que tous les paragraphes d’un document soient centrés, vous pouvez sélectionner tous les paragraphes du contrôle et définir la SelectionAlignment propriété HorizontalAlignment.Centersur .

Note

SelectionAlignment retourne SelectionAlignment.Left lorsque la sélection de texte contient plusieurs paragraphes avec un alignement mixte.

S’applique à

Voir aussi