Compartilhar via


Label.AutoSize Propriedade

Definição

Obtém ou define um valor que indica se o controle é redimensionado automaticamente para exibir todo o conteúdo.

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 da propriedade

true se o controle ajustar sua largura para ajustar seu conteúdo de perto; caso contrário, false. Quando adicionado a um formulário usando o designer, o valor padrão é true. Quando instanciado do código, o valor padrão é false.

Atributos

Exemplos

O exemplo de código a seguir demonstra a AutoSize propriedade. Para executar este exemplo, cole o código a seguir em um formulário e chame o InitializeLabel método do construtor ou Load método do formulário.

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

Comentários

Quando essa propriedade é definida como true, ela Label ajusta sua largura para exibir todo o conteúdo. Essa propriedade normalmente é definida true para quando você usa um Label controle para exibir vários comprimentos de texto, como o status de um processo de aplicativo. Você também pode usar essa propriedade quando o aplicativo exibir o texto em vários idiomas e o tamanho do texto pode aumentar ou diminuir com base nas configurações de idioma no Windows.

Importante

Se a fonte for mais alta que a altura do Label e AutoEllipsis fortrue, você deverá definir falseAutoSize para que o texto seja desenhado.

Aplica-se a

Confira também