Label.AutoSize Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy rozmiar kontrolki jest automatycznie zmieniany w celu wyświetlenia całej zawartości.

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

Wartość właściwości

Boolean

true jeżeli kontrolka dopasowuje jej szerokość, aby dokładnie pasowała do jej zawartości; w przeciwnym razie , false. Po dodaniu do formularza przy użyciu projektanta wartość domyślna to true. Po utworzeniu wystąpienia z kodu wartość domyślna to false.

Atrybuty

Przykłady

Poniższy przykład kodu przedstawia AutoSize właściwość . Aby uruchomić ten przykład, wklej następujący kod w formularzu i wywołaj InitializeLabel metodę z konstruktora lub Load metody formularza.

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

Uwagi

Gdy ta właściwość jest ustawiona na true, Label dopasowuje jej szerokość, aby wyświetlić całą zawartość. Ta właściwość jest zwykle ustawiana na true wartość , gdy używasz Label kontrolki do wyświetlania różnych długości tekstu, takich jak stan procesu aplikacji. Można również użyć tej właściwości, gdy aplikacja będzie wyświetlać tekst w różnych językach, a rozmiar tekstu może wzrosnąć lub zmniejszyć w zależności od ustawień języka w Windows.

Ważne

Jeśli czcionka jest wyższa niż wysokość Label obiektu i AutoEllipsis to true, należy ustawić false wartość AutoSize na , aby tekst został narysowany.

Dotyczy

Zobacz też