Label.PreferredHeight Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Denetimin tercih edilen yüksekliğini alır.
public:
virtual property int PreferredHeight { int get(); };
[System.ComponentModel.Browsable(false)]
public virtual int PreferredHeight { get; }
[<System.ComponentModel.Browsable(false)>]
member this.PreferredHeight : int
Public Overridable ReadOnly Property PreferredHeight As Integer
Özellik Değeri
Tek bir metin satırının görüntülendiği varsayılarak denetimin yüksekliği (piksel cinsinden).
- Öznitelikler
Örnekler
Aşağıdaki kod örneği, ve özellikleri kullanılarak üç boyutlu kenarlık ve görüntü görüntü içeren bir denetimin ImageListImageIndex nasıl oluşturulacağını Label gösterir. Denetimin ayrıca, belirtilen bir anımsatıcı karakteri olan bir resim yazısı da vardır. Örnek kod, denetimin görüntülendiği formda düzgün şekilde boyutlandırılmalarını Label sağlamak için ve PreferredWidth özelliklerini kullanırPreferredHeight. Bu örnek, bir ImageList öğesinin oluşturulmasını ve imageList1 olarak adlandırıldığını ve iki görüntü yüklemiş olmasını gerektirir. Örnek ayrıca kodun ad alanının koduna eklendiği bir formda System.Drawing olmasını gerektirir.
public:
void CreateMyLabel()
{
// Create an instance of a Label.
Label^ label1 = gcnew Label;
// Set the border to a three-dimensional border.
label1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
// Set the ImageList to use for displaying an image.
label1->ImageList = imageList1;
// Use the second image in imageList1.
label1->ImageIndex = 1;
// Align the image to the top left corner.
label1->ImageAlign = ContentAlignment::TopLeft;
// Specify that the text can display mnemonic characters.
label1->UseMnemonic = true;
// Set the text of the control and specify a mnemonic character.
label1->Text = "First &Name:";
/* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
label1->Size = System::Drawing::Size( label1->PreferredWidth, label1->PreferredHeight );
//...Code to add the control to the form...
}
public void CreateMyLabel()
{
// Create an instance of a Label.
Label label1 = new Label();
// Set the border to a three-dimensional border.
label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
// Set the ImageList to use for displaying an image.
label1.ImageList = imageList1;
// Use the second image in imageList1.
label1.ImageIndex = 1;
// Align the image to the top left corner.
label1.ImageAlign = ContentAlignment.TopLeft;
// Specify that the text can display mnemonic characters.
label1.UseMnemonic = true;
// Set the text of the control and specify a mnemonic character.
label1.Text = "First &Name:";
/* Set the size of the control based on the PreferredHeight and PreferredWidth values. */
label1.Size = new Size (label1.PreferredWidth, label1.PreferredHeight);
//...Code to add the control to the form...
}
Public Sub CreateMyLabel()
' Create an instance of a Label.
Dim label1 As New Label()
' Set the border to a three-dimensional border.
label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
' Set the ImageList to use for displaying an image.
label1.ImageList = imageList1
' Use the second image in imageList1.
label1.ImageIndex = 1
' Align the image to the top left corner.
label1.ImageAlign = ContentAlignment.TopLeft
' Specify that the text can display mnemonic characters.
label1.UseMnemonic = True
' Set the text of the control and specify a mnemonic character.
label1.Text = "First &Name:"
' Set the size of the control based on the PreferredHeight and PreferredWidth values.
label1.Size = New Size(label1.PreferredWidth, label1.PreferredHeight)
'...Code to add the control to the form...
End Sub
Açıklamalar
Bu özellik, denetime atanan yazı tipine bağlı olarak metnin düzgün görüntülenmesi için denetimin olması gereken yüksekliği döndürür. Denetimdeki Label metnin düzgün görüntülendiğinden PreferredWidth emin olmak için bu özelliği özelliğiyle birlikte kullanabilirsiniz. özelliğini kullanarak denetimin AutoSize yüksekliğini ve genişliğini Label metin ve yazı tipi boyutuna göre otomatik olarak ayarlayabilirsiniz.
Uyarı
Denetimin BorderStyleLabel özelliği olarak BorderStyle.Noneayarlanırsa, özellik tarafından PreferredHeight döndürülen değer kenarlıkların olmaması nedeniyle daha büyük olur.