Label.PreferredHeight 속성

정의

이 컨트롤의 기본 설정 높이를 가져옵니다.

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

속성 값

한 줄의 텍스트가 표시되는 것으로 가정하는 컨트롤의 높이(단위: 픽셀)입니다.

특성

예제

다음 코드 예제를 만드는 Label 방법에 설명 합니다 3 차원 테두리와 이미지를 사용 하 여 ImageList 표시 되는 컨트롤을 및 ImageIndex 속성입니다. 또한 컨트롤에는 니모닉 문자가 지정된 캡션이 있습니다. 예제 코드는 및 PreferredWidth 속성을 사용하여 PreferredHeight 컨트롤이 표시되는 폼의 Label 컨트롤 크기를 적절하게 조정합니다. 이 예제에서는 ImageList 가 만들어지고 이름이 imageList1이고 두 개의 이미지를 로드해야 합니다. 이 예제에서는 코드가 해당 코드에 추가된 네임스페이스가 System.Drawing 있는 양식 내에 있어야 합니다.

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

설명

이 속성은 컨트롤에 할당된 글꼴에 따라 텍스트를 제대로 표시하기 위해 컨트롤이 있어야 하는 높이를 반환합니다. 컨트롤의 텍스트 LabelPreferredWidth 제대로 표시되도록 속성과 함께 이 속성을 사용할 수 있습니다. 사용 하 여는 AutoSize 속성을 자동으로 높이와 너비 Label 를 조정할 수 있습니다는 텍스트 및 글꼴 크기에 따라 컨트롤입니다.

참고

경우는 BorderStyle 의 속성을 Label 컨트롤을 로 설정 BorderStyle.None합니다 속성에서 PreferredHeight 반환 된 값이 더 큰 테두리의 부족으로 인해 합니다.

적용 대상

추가 정보