Label.AutoSize Label.AutoSize Label.AutoSize Label.AutoSize Property

Definición

Obtiene o establece un valor que indica si el control cambia automáticamente de tamaño para mostrar todo su contenido.Gets or sets a value indicating whether the control is automatically resized to display its entire contents.

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

Valor de propiedad

true si el control ajusta su ancho al contenido; en caso contrario, es false.true if the control adjusts its width to closely fit its contents; otherwise, false.


Cuando se agrega a un formulario utilizando el diseñador, el valor predeterminado es true.When added to a form using the designer, the default value is true. Cuando se crean instancias desde el código, el valor predeterminado es false.When instantiated from code, the default value is false.

Ejemplos

En el ejemplo de código siguiente AutoSize se muestra la propiedad.The following code example demonstrates the AutoSize property. Para ejecutar este ejemplo, pegue el código siguiente en un formulario y llame InitializeLabel al método desde el constructor o Load método del formulario.To run this example, paste the following code in a form and call the InitializeLabel method from the form's constructor or Load method.

   // 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 en true, el Label ajusta su ancho para mostrar todo su contenido.When this property is set to true, the Label adjusts its width to display its entire contents. Esta propiedad se establece normalmente en true cuando se usa un Label control para mostrar varias longitudes de texto, como el estado de un proceso de aplicación.This property is typically set to true when you use a Label control to display various lengths of text, such as the status of an application process. 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.You can also use this property when the application will display text in various languages, and the size of the text might increase or decrease based on the language settings in Windows.

Importante

Si la fuente es más alta que el alto de Label y AutoEllipsis es true, debe establecer AutoSize en false para dibujar el texto.If the font is taller than the height of the Label and AutoEllipsis is true, you must set AutoSize to false for text to be drawn.

Se aplica a

Consulte también: