Label.AutoSize Vlastnost
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Získá nebo nastaví hodnotu určující, zda je ovládací prvek automaticky změněn tak, aby zobrazoval celý jeho obsah.
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
Hodnota vlastnosti
truepokud ovládací prvek upraví jeho šířku tak, aby přesně odpovídal jeho obsahu; v opačném případě . false Při přidání do formuláře pomocí návrháře je truevýchozí hodnota . Při vytváření instance z kódu je falsevýchozí hodnota .
- Atributy
Příklady
Následující příklad kódu ukazuje AutoSize vlastnost. Pokud chcete tento příklad spustit, vložte do formuláře následující kód a zavolejte metodu InitializeLabel z konstruktoru nebo Load metody formuláře.
// 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
Poznámky
Pokud je tato vlastnost nastavena na true, Label upraví její šířku tak, aby zobrazovala celý její obsah. Tato vlastnost je obvykle nastavena, true když používáte Label ovládací prvek k zobrazení různých délek textu, například stav procesu aplikace. Tuto vlastnost můžete také použít, když aplikace zobrazí text v různých jazycích a velikost textu se může zvětšit nebo zmenšit v závislosti na nastavení jazyka ve Windows.
Důležité
Pokud je písmo vyšší než výška Label a AutoEllipsis je true, je nutné nastavit AutoSize , aby false byl text nakreslen.