Leggere in inglese

Condividi tramite


StringAlignment Enumerazione

Definizione

Specifica l'allineamento di una stringa di testo in relazione al suo rettangolo di layout.

C#
public enum StringAlignment
Ereditarietà
StringAlignment

Campi

Nome Valore Descrizione
Center 1

Specifica che il testo è allineato al centro del rettangolo di layout.

Far 2

Specifica che il testo è allineato in una posizione lontana da quella di origine del rettangolo di layout. In un layout da sinistra a destra, tale posizione si trova a destra. In un layout da destra a sinistra, invece, si trova a sinistra.

Near 0

Specifica che il testo è allineato in una posizione vicina al layout. In un layout da sinistra a destra, tale posizione si trova a sinistra. In un layout da destra a sinistra, invece, si trova a destra.

Esempio

Nell'esempio di codice seguente viene illustrato come usare le LineAlignment proprietà e e l'enumerazione AlignmentStringAlignment per allineare le stringhe. Questo esempio è progettato per essere usato con Windows Forms. Incollare il codice in un modulo e chiamare il ShowLineAndAlignment metodo durante la gestione dell'evento del Paint modulo, passando e come PaintEventArgs .

C#
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);
}

Commenti

Se usato con la proprietà, questa enumerazione imposta l'allineamento LineAlignment verticale per una stringa disegnata. Se usato con la proprietà, questa enumerazione imposta l'allineamento Alignment orizzontale.

Si applica a

Prodotto Versioni
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9