StringAlignment Enumeração

Definição

Especifica o alinhamento da cadeia de caracteres de um texto em relação ao seu retângulo de layout.Specifies the alignment of a text string relative to its layout rectangle.

public enum class StringAlignment
public enum StringAlignment
type StringAlignment = 
Public Enum StringAlignment
Herança
StringAlignment

Campos

Center 1

Especifica que o texto é alinhado no centro do retângulo de layout.Specifies that text is aligned in the center of the layout rectangle.

Far 2

Especifica que o texto é alinhado longe da posição de origem do retângulo de layout.Specifies that text is aligned far from the origin position of the layout rectangle. Em um layout da esquerda para a direita, a posição mais distante é à direita.In a left-to-right layout, the far position is right. Em um layout da direita para a esquerda, a posição mais distante é à esquerda.In a right-to-left layout, the far position is left.

Near 0

Especifica que o texto seja alinhado perto do layout.Specifies the text be aligned near the layout. Em um layout da esquerda para a direita, a posição aproximada é à esquerda.In a left-to-right layout, the near position is left. Em um layout da direita para a esquerda, a posição aproximada é à direita.In a right-to-left layout, the near position is right.

Exemplos

O exemplo de código a seguir demonstra como usar as propriedades LineAlignment e Alignment e a enumeração StringAlignment para alinhar cadeias de caracteres.The following code example demonstrates how to use the LineAlignment and Alignment properties and the StringAlignment enumeration to align strings. Este exemplo foi projetado para ser usado com Windows Forms.This example is designed to be used with Windows Forms. Cole o código em um formulário e chame o método ShowLineAndAlignment ao manipular o evento Paint do formulário, passando e como PaintEventArgs.Paste 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

Comentários

Quando usado com a propriedade LineAlignment, essa enumeração define o alinhamento vertical de uma cadeia de caracteres de desenho.When used with the LineAlignment property, this enumeration sets the vertical alignment for a drawn string. Quando usado com a propriedade Alignment, essa enumeração define o alinhamento horizontal.When used with the Alignment property, this enumeration sets the horizontal alignment.

Aplica-se a