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

定義

取得或設定值,指出控制項是否自動調整大小以顯示其全部內容。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

屬性值

如果控制項會配合內容調整寬度,則為 true,否則為 falsetrue if the control adjusts its width to closely fit its contents; otherwise, false.


使用設計工具加入至表單時,預設值為 trueWhen added to a form using the designer, the default value is true. 從程式碼具現化時,預設值為 falseWhen instantiated from code, the default value is false.

範例

下列程式碼範例會示範AutoSize屬性。The following code example demonstrates the AutoSize property. 若要執行此範例,請在表單中貼上下列程式InitializeLabel代碼,並從表單的Load函式或方法呼叫方法。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

備註

當這個屬性設定為trueLabel ,會調整其寬度以顯示其完整內容。When this property is set to true, the Label adjusts its width to display its entire contents. 當您true Label使用控制項來顯示各種長度的文字(例如應用程式進程的狀態)時,這個屬性通常會設定為。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. 當應用程式將以各種語言顯示文字時,您也可以使用這個屬性,而文字的大小可能會根據 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.

重要

如果Label字型高於的高度,且AutoEllipsistrue,則您必須將設AutoSizefalse ,才能繪製文字。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.

適用於

另請參閱