Label.AutoSize 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示是否自动调整控件的大小以显示其完整内容。
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
属性值
如果控件调整宽度以完整显示内容,值为 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,true
AutoEllipsis则必须设置为AutoSizefalse
要绘制文本。