StringFormat.Alignment Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene o establece la alineación horizontal de la cadena.
public:
property System::Drawing::StringAlignment Alignment { System::Drawing::StringAlignment get(); void set(System::Drawing::StringAlignment value); };
public System.Drawing.StringAlignment Alignment { get; set; }
member this.Alignment : System.Drawing.StringAlignment with get, set
Public Property Alignment As StringAlignment
Valor de propiedad
Enumeración StringAlignment que especifica la alineación horizontal de la cadena.
Ejemplos
En el ejemplo de código siguiente se muestra cómo usar las LineAlignment propiedades y Alignment y la StringAlignment enumeración para alinear cadenas. Este ejemplo está diseñado para usarse con Windows Forms. Pegue el código en un formulario y llame al ShowLineAndAlignment
método al controlar el evento del Paint formulario, pasando e
como 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
Use LineAlignment para especificar la alineación vertical de la cadena.