Label.AutoSize Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta un valore che indica se il controllo viene ridimensionato automaticamente per visualizzarne l'intero contenuto.
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
Valore della proprietà
true se il controllo regola la sua larghezza in modo da adattarne il contenuto; in caso contrario, false. Quando viene aggiunto a un modulo tramite la finestra di progettazione, il valore predefinito è true. Quando viene creata un'istanza dal codice, il valore predefinito è false.
- Attributi
Esempio
Nell'esempio di codice seguente viene illustrata la AutoSize proprietà . Per eseguire questo esempio, incollare il codice seguente in una maschera e chiamare il InitializeLabel metodo dal costruttore o Load dal metodo del modulo.
// 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
Commenti
Quando questa proprietà è impostata su true, regola Label la larghezza per visualizzarne l'intero contenuto. Questa proprietà viene in genere impostata su true quando si usa un Label controllo per visualizzare varie lunghezze di testo, ad esempio lo stato di un processo dell'applicazione. È anche possibile utilizzare questa proprietà quando l'applicazione visualizzerà il testo in varie lingue e le dimensioni del testo potrebbero aumentare o diminuire in base alle impostazioni della lingua in Windows.
Importante
Se il tipo di carattere è più alto dell'altezza di Label e AutoEllipsis è true, è necessario impostare su falseAutoSize per il testo da disegnare.