Aracılığıyla paylaş


Label.PreferredWidth Özellik

Tanım

Denetimin tercih edilen genişliğini alır.

public:
 virtual property int PreferredWidth { int get(); };
[System.ComponentModel.Browsable(false)]
public virtual int PreferredWidth { get; }
[<System.ComponentModel.Browsable(false)>]
member this.PreferredWidth : int
Public Overridable ReadOnly Property PreferredWidth As Integer

Özellik Değeri

Tek bir metin satırının görüntülendiği varsayılarak denetimin genişliğ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 metin dizesinin uzunluğunu döndürür, ancak satır kaydırmayı dikkate almaz. Örneğin, 300 piksel genişliğindeki bir metin dizesi, yalnızca 100 piksel genişliğinde bir Label içinde üç satır olarak görüntülenebilir. PreferredWidth özelliği hala 300 piksel döndürür. Denetimdeki Label metnin düzgün görüntülendiğinden PreferredHeight 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 PreferredWidth döndürülen değer kenarlıkların olmaması nedeniyle daha büyük olur.

Şunlara uygulanır

Ayrıca bkz.