Label.AutoSize Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau menetapkan nilai yang menunjukkan apakah kontrol diubah ukurannya secara otomatis untuk menampilkan seluruh isinya.
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
Nilai Properti
true jika kontrol menyesuaikan lebarnya agar pas dengan isinya; jika tidak, false. Saat ditambahkan ke formulir menggunakan perancang, nilai defaultnya adalah true. Ketika dibuat dari kode, nilai defaultnya adalah false.
- Atribut
Contoh
Contoh kode berikut menunjukkan AutoSize properti . Untuk menjalankan contoh ini, tempelkan kode berikut dalam formulir dan panggil InitializeLabel metode dari konstruktor atau Load metode formulir.
// 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
Keterangan
Ketika properti ini diatur ke true, menyesuaikan Label lebarnya untuk menampilkan seluruh isinya. Properti ini biasanya diatur ke true saat Anda menggunakan Label kontrol untuk menampilkan berbagai panjang teks, seperti status proses aplikasi. Anda juga dapat menggunakan properti ini ketika aplikasi akan menampilkan teks dalam berbagai bahasa, dan ukuran teks mungkin meningkat atau berkurang berdasarkan pengaturan bahasa di Windows.
Penting
Jika font lebih tinggi dari tinggi Label dan AutoEllipsis , trueAnda harus mengatur AutoSize ke false agar teks digambar.