RichTextBox.SelectionAlignment Propriété

Définition

Obtient ou définit l'alignement à appliquer à la sélection ou au point d'insertion en cours.

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 valeurs de l'objet HorizontalAlignment.

Attributs

Exceptions

La valeur spécifiée n'est pas une valeur définie dans la classe HorizontalAlignment.

Exemples

L’exemple de code suivant montre comment aligner le texte dans .RichTextBox Cet exemple nécessite qu’un RichTextBox contrôle, nommé richTextBox1, ait é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 paragraphe qui a 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é sur HorizontalAlignment.Center, le paragraphe au point d’insertion sera centré dans le contrôle. Si un troisième paragraphe est créé après le deuxième paragraphe, il est également aligné sur le 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 .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é sur HorizontalAlignment.Center.

Notes

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

S’applique à

Voir aussi