Label.AutoSize Propiedad

Definición

Obtiene o establece un valor que indica si el control cambia automáticamente de tamaño para mostrar todo su contenido.

public:
 virtual property bool AutoSize { bool get(); void set(bool value); };
public virtual bool AutoSize { get; set; }
[System.ComponentModel.Browsable(true)]
public override bool AutoSize { get; set; }
member this.AutoSize : bool with get, set
[<System.ComponentModel.Browsable(true)>]
member this.AutoSize : bool with get, set
Public Overridable Property AutoSize As Boolean
Public Overrides Property AutoSize As Boolean

Valor de propiedad

Boolean

true si el control ajusta su ancho al contenido; en caso contrario, es false. Cuando se agrega a un formulario utilizando el diseñador, el valor predeterminado es true. Cuando se crean instancias desde el código, el valor predeterminado es false.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra la AutoSize propiedad . Para ejecutar este ejemplo, pegue el código siguiente en un formulario y llame al InitializeLabel método desde el constructor o Load método del formulario.

   // Declare a label.
internal:
   System::Windows::Forms::Label ^ Label1;

private:

   // Initialize the label.
   void InitializeLabel()
   {
      this->Label1 = gcnew Label;
      this->Label1->Location = System::Drawing::Point( 10, 10 );
      this->Label1->Name = "Label1";
      this->Label1->TabIndex = 0;
      
      // Set the label to a small size, but set the AutoSize property 
      // to true. The label will adjust its length so all the text
      // is visible, however if the label is wider than the form,
      // the entire label will not be visible.
      this->Label1->Size = System::Drawing::Size( 10, 10 );
      this->Controls->Add( this->Label1 );
      this->Label1->AutoSize = true;
      this->Label1->Text = "The text in this label is longer"
      " than the set size.";
   }
// Declare a label.
internal System.Windows.Forms.Label Label1;

// Initialize the label.
private void InitializeLabel()
{
    this.Label1 = new Label();
    this.Label1.Location = new System.Drawing.Point(10, 10);
    this.Label1.Name = "Label1";
    this.Label1.TabIndex = 0;

    // Set the label to a small size, but set the AutoSize property 
    // to true. The label will adjust its length so all the text
    // is visible, however if the label is wider than the form,
    // the entire label will not be visible.
    this.Label1.Size = new System.Drawing.Size(10, 10);
    this.Controls.Add(this.Label1);
    this.Label1.AutoSize = true;
    this.Label1.Text = "The text in this label is longer" +  
        " than the set size.";
}
' Declare a label.
Friend WithEvents Label1 As System.Windows.Forms.Label

' Initialize the label.
Private Sub InitializeLabel()
    Me.Label1 = New Label
    Me.Label1.Location = New System.Drawing.Point(10, 10)
    Me.Label1.Name = "Label1"
    Me.Label1.TabIndex = 0

    ' Set the label to a small size, but set the AutoSize property 
    ' to true. The label will adjust its length so all the text
    ' is visible, however if the label is wider than the form,
    ' the entire label will not be visible.
    Me.Label1.Size = New System.Drawing.Size(10, 10)
    Me.Controls.Add(Me.Label1)
    Me.Label1.AutoSize = True
    Me.Label1.Text = "The text in this label is longer than the set size."

End Sub

Comentarios

Cuando esta propiedad se establece trueen , Label ajusta su ancho para mostrar todo su contenido. Esta propiedad se establece true normalmente en cuando se usa un Label control para mostrar varias longitudes de texto, como el estado de un proceso de aplicación. También puede usar esta propiedad cuando la aplicación muestre texto en varios idiomas y el tamaño del texto puede aumentar o disminuir en función de la configuración de idioma de Windows.

Importante

Si la fuente es más alta que el alto de Label y AutoEllipsis es true, debe establecer AutoSize en false para que se dibuje el texto.

Se aplica a

Consulte también