HorizontalAlignment Énumération
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Spécifie comment un objet ou du texte dans un contrôle est aligné horizontalement par rapport à un élément du contrôle.
public enum class HorizontalAlignment
[System.Runtime.InteropServices.ComVisible(true)]
public enum HorizontalAlignment
[<System.Runtime.InteropServices.ComVisible(true)>]
type HorizontalAlignment =
Public Enum HorizontalAlignment
- Héritage
- Attributs
Champs
| Nom | Valeur | Description |
|---|---|---|
| Left | 0 | L’objet ou le texte est aligné à gauche de l’élément de contrôle. |
| Right | 1 | L’objet ou le texte est aligné à droite de l’élément de contrôle. |
| Center | 2 | L’objet ou le texte est aligné au centre de l’élément de contrôle. |
Exemples
Cet exemple montre comment utiliser l’énumération HorizontalAlignment pour aligner le texte à gauche, à droite ou au centre d’un élément de contrôle. Tout d’abord, créez une TextBox taille spécifique et ajoutez-y une chaîne de texte. Ensuite, utilisez le membre Center d’énumération pour aligner le texte au centre du TextBox. L’exemple part du principe que vous avez créé un Form nom Form1 et un nommé .textBox1TextBox
private:
void Form1_Load( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
// Add a text String* to the TextBox.
textBox1->Text = "Hello World!";
// Set the size of the TextBox.
textBox1->AutoSize = false;
textBox1->Size = System::Drawing::Size( Width, Height / 3 );
// Align the text in the center of the control element.
textBox1->TextAlign = HorizontalAlignment::Center;
}
private void Form1_Load(object sender, System.EventArgs e)
{
// Add a text string to the TextBox.
textBox1.Text = "Hello World!";
// Set the size of the TextBox.
textBox1.AutoSize = false;
textBox1.Size = new Size(Width, Height/3);
// Align the text in the center of the control element.
textBox1.TextAlign = HorizontalAlignment.Center;
}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Add a text string to the TextBox.
TextBox1.Text = "Hello World!"
' Set the size of the TextBox.
TextBox1.AutoSize = False
TextBox1.Size = New Size(Width, Height/3)
' Align the text in the center of the control element.
TextBox1.TextAlign = HorizontalAlignment.Center
End Sub
Remarques
Cette énumération est utilisée dans de nombreuses classes. Une liste partielle de ces classes est CheckedListBox, , ColumnHeader, ControlPaintComboBoxLabel, ListBox, Control, , RichTextBox, , et .TextBox