StringAlignment StringAlignment StringAlignment StringAlignment Enum

Definición

Determina la alineación de una cadena de texto en relación con el rectángulo de diseño correspondiente.Specifies the alignment of a text string relative to its layout rectangle.

public enum class StringAlignment
public enum StringAlignment
type StringAlignment = 
Public Enum StringAlignment
Herencia
StringAlignmentStringAlignmentStringAlignmentStringAlignment

Campos

Center Center Center Center 1

Determina que el texto se alinea en el centro del rectángulo de diseño.Specifies that text is aligned in the center of the layout rectangle.

Far Far Far Far 2

Determina que el texto se alinea alejado de la posición de origen del rectángulo de diseño.Specifies that text is aligned far from the origin position of the layout rectangle. En un diseño de izquierda a derecha, la posición más alejada es la de la derecha.In a left-to-right layout, the far position is right. En un diseño de derecha a izquierda, la posición más alejada es la de la izquierda.In a right-to-left layout, the far position is left.

Near Near Near Near 0

Determina que el texto se alinea cerca del diseño.Specifies the text be aligned near the layout. En un diseño de izquierda a derecha, la posición cercana es la de la izquierda.In a left-to-right layout, the near position is left. En un diseño de derecha a izquierda, la posición cercana es la de la derecha.In a right-to-left layout, the near position is right.

Ejemplos

En el ejemplo de código siguiente se muestra cómo LineAlignment usar Alignment las propiedades y StringAlignment y la enumeración para alinear cadenas.The following code example demonstrates how to use the LineAlignment and Alignment properties and the StringAlignment enumeration to align strings. Este ejemplo está diseñado para usarse con Windows Forms.This example is designed to be used with Windows Forms. Pegue el código en un formulario y ShowLineAndAlignment llame al método al controlar el evento del Paint formulario, pasando e como. PaintEventArgsPaste the code into a form and call the ShowLineAndAlignment method when handling the form's Paint event, passing e as PaintEventArgs .

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.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 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

Comentarios

Cuando se usa con LineAlignment la propiedad, esta enumeración establece la alineación vertical de una cadena dibujada.When used with the LineAlignment property, this enumeration sets the vertical alignment for a drawn string. Cuando se usa con Alignment la propiedad, esta enumeración establece la alineación horizontal.When used with the Alignment property, this enumeration sets the horizontal alignment.

Se aplica a