共用方式為


Label.AutoSize 屬性

定義

取得或設定值,指出控制項是否自動調整大小以顯示其全部內容。

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

屬性值

Boolean

如果控制項會配合內容調整寬度,則為 true,否則為 false。 使用設計工具加入至表單時,預設值為 true。 從程式碼具現化時,預設值為 false

屬性

範例

下列程式碼範例示範 AutoSize 屬性。 若要執行此範例,請在表單中貼上下列程式碼,並從表單的建構函式或 Load 方法呼叫 InitializeLabel 方法。

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

備註

當此屬性設定為 true 時,會 Label 調整其寬度以顯示其整個內容。 當您使用 Label 控制項來顯示各種文字長度時,此屬性通常會設定 true 為 ,例如應用程式進程的狀態。 當應用程式以各種語言顯示文字時,您也可以使用這個屬性,而文字的大小可能會根據Windows中的語言設定而增加或減少。

重要

如果字型高於 Label 的高度,且 AutoEllipsistrue ,您必須將 設定 AutoSize false 為 ,才能繪製文字。

適用於

另請參閱