Assembly : System.Drawing (dans system.drawing.dll)
SyntaxePublic Enumeration StringAlignment
Dim instance As StringAlignment
public enum StringAlignment
public enum class StringAlignment
public enum StringAlignment
public enum StringAlignment
Membres| Nom de membre | Description | |
|---|---|---|
![]() | Center | Spécifie que le texte est aligné au centre du rectangle de mise en page. |
![]() | Far | Spécifie que le texte est aligné loin de la position d'origine du rectangle de mise en page. Dans une mise en page de gauche à droite, la position éloignée est à droite. Dans une mise en page de droite à gauche, la position éloignée est à gauche. |
![]() | Near | Spécifie que le texte doit être aligné près de la mise en page. Dans une mise en page de droite à gauche, la position proche est à gauche. Dans une mise en page de gauche à droite, la position proche est à droite. |
NotesLorsqu'utilisée avec la propriété LineAlignment, cette énumération définit l'alignement vertical d'une chaîne de caractères dessinée. Lorsqu'utilisée avec la propriété Alignment, cette énumération définit l'alignement horizontal.
ExempleL'exemple de code suivant montre comment utiliser les propriétés LineAlignment et Alignment et l'énumération StringAlignment pour aligner les chaînes de caractères. Cet exemple est conçu pour être utilisé avec Windows Forms. Collez le code dans un formulaire et appelez la méthode ShowLineAndAlignment lors de la gestion de l'événement Paint du formulaire, en passant e comme PaintEventArgs.
Private Sub ShowLineAndAlignment(ByVal e As PaintEventArgs) ' Construct a new Rectangle. Dim displayRectangle _ As New Rectangle(New Point(40, 40), New Size(80, 80)) ' Construct two new StringFormat objects Dim format1 As New StringFormat(StringFormatFlags.NoClip) Dim format2 As New StringFormat(format1) ' Set the LineAlignment and Alignment properties for ' both StringFormat objects to different values. format1.LineAlignment = StringAlignment.Near format1.Alignment = StringAlignment.Center format2.LineAlignment = StringAlignment.Center format2.Alignment = StringAlignment.Far ' Draw the bounding rectangle and a string for each ' StringFormat object. e.Graphics.DrawRectangle(Pens.Black, displayRectangle) e.Graphics.DrawString("Showing Format1", Me.Font, Brushes.Red, _ RectangleF.op_Implicit(displayRectangle), format1) e.Graphics.DrawString("Showing Format2", Me.Font, Brushes.Red, _ RectangleF.op_Implicit(displayRectangle), format2) End Sub
private void ShowLineAndAlignment(PaintEventArgs e) { // Construct a new Rectangle . Rectangle displayRectangle = new Rectangle (new Point(40, 40), new Size (80, 80)); // Construct 2 new StringFormat objects StringFormat format1 = new StringFormat(StringFormatFlags.NoClip); StringFormat format2 = new StringFormat(format1); // Set the LineAlignment and Alignment properties for // both StringFormat objects to different values. format1.LineAlignment = StringAlignment.Near; format1.Alignment = StringAlignment.Center; format2.LineAlignment = StringAlignment.Center; format2.Alignment = StringAlignment.Far; // Draw the bounding rectangle and a string for each // StringFormat object. e.Graphics.DrawRectangle(Pens.Black, displayRectangle); e.Graphics.DrawString("Showing Format1", this.Font, Brushes.Red, (RectangleF)displayRectangle, format1); e.Graphics.DrawString("Showing Format2", this.Font, Brushes.Red, (RectangleF)displayRectangle, format2); }
private: void ShowLineAndAlignment( PaintEventArgs^ e ) { // Construct a new Rectangle . Rectangle displayRectangle = Rectangle(Point(40,40),System::Drawing::Size( 80, 80 )); // Construct 2 new StringFormat objects StringFormat^ format1 = gcnew StringFormat( StringFormatFlags::NoClip ); StringFormat^ format2 = gcnew StringFormat( format1 ); // Set the LineAlignment and Alignment properties for // both StringFormat objects to different values. format1->LineAlignment = StringAlignment::Near; format1->Alignment = StringAlignment::Center; format2->LineAlignment = StringAlignment::Center; format2->Alignment = StringAlignment::Far; // Draw the bounding rectangle and a string for each // StringFormat object. e->Graphics->DrawRectangle( Pens::Black, displayRectangle ); e->Graphics->DrawString( "Showing Format1", this->Font, Brushes::Red, displayRectangle, format1 ); e->Graphics->DrawString( "Showing Format2", this->Font, Brushes::Red, displayRectangle, format2 ); }
private void ShowLineAndAlignment(PaintEventArgs e) { // Construct a new Rectangle . Rectangle displayRectangle = new Rectangle(new Point(40, 40), new Size(80, 80)); // Construct 2 new StringFormat objects StringFormat format1 = new StringFormat(StringFormatFlags.NoClip); StringFormat format2 = new StringFormat(format1); // Set the LineAlignment and Alignment properties for // both StringFormat objects to different values. format1.set_LineAlignment(StringAlignment.Near); format1.set_Alignment(StringAlignment.Center); format2.set_LineAlignment(StringAlignment.Center); format2.set_Alignment(StringAlignment.Far); // Draw the bounding rectangle and a string for each // StringFormat object. e.get_Graphics().DrawRectangle(Pens.get_Black(), displayRectangle); e.get_Graphics().DrawString("Showing Format1", this.get_Font(), Brushes.get_Red(), (RectangleF.op_Implicit((displayRectangle))), format1); e.get_Graphics().DrawString("Showing Format2", this.get_Font(), Brushes.get_Red(), RectangleF.op_Implicit((displayRectangle)), format2); } //ShowLineAndAlignment
Plates-formesWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.
Informations de version
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ