Label.PreferredHeight Property

Definition

이 컨트롤의 기본 설정 높이를 가져옵니다.Gets the preferred height of the control.

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

Property Value

Int32

한 줄의 텍스트가 표시되는 것으로 가정하는 컨트롤의 높이(단위: 픽셀)입니다.The height of the control (in pixels), assuming a single line of text is displayed.

Attributes

Examples

다음 코드 예제에서는 ImageListImageIndex 속성을 사용 하 여 3 차원 테두리와 이미지를 표시 하는 Label 컨트롤을 만드는 방법을 보여 줍니다.The following code example demonstrates how to create a Label control that has a three-dimensional border and an image displayed using the ImageList and ImageIndex properties. 컨트롤에 지정 된 니모닉 문자를 사용 하 여는 캡션이 있습니다.The control also has a caption with a mnemonic character specified. 예제 코드는 PreferredHeightPreferredWidth 속성을 사용 하 여 표시 되는 폼에서 Label 컨트롤의 크기를 적절히 조정 합니다.The example code uses the PreferredHeight and PreferredWidth properties to properly size the Label control on the form on which it is displayed. 이 예에서는 ImageList을 만들고 이름을 imageList1로 지정 하 고 두 개의 이미지를 로드 해야 합니다.This example requires that an ImageList has been created and named imageList1 and that it has loaded two images. 또한이 예제에서는 코드에 System.Drawing 네임 스페이스를 추가 하는 폼 안에 코드가 있어야 합니다.The example also requires that the code is within a form that has the System.Drawing namespace added to its code.

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

Remarks

이 컨트롤은 컨트롤에 사용 된 글꼴에 따라 텍스트를 올바르게 표시 하기 위해 수 있어야 하는 높이 반환 합니다.This property returns the height that the control should be in order to properly display text, based on the font assigned to the control. PreferredWidth 속성과 함께이 속성을 사용 하 여 Label 컨트롤의 텍스트가 제대로 표시 되도록 할 수 있습니다.You can use this property along with the PreferredWidth property to ensure that the text in the Label control is displayed properly. AutoSize 속성을 사용 하 여 텍스트 및 글꼴 크기에 따라 Label 컨트롤의 높이와 너비를 자동으로 조정할 수 있습니다.You can use the AutoSize property to automatically adjust the height and the width of the Label control, based on the text and font size.

Note

Label 컨트롤의 BorderStyle 속성이 BorderStyle.None로 설정 된 경우에는 PreferredHeight 속성에 의해 반환 된 값이 테두리가 없기 때문에 더 커집니다.If the BorderStyle property of the Label control is set to BorderStyle.None, the value returned by PreferredHeight property will be larger due to the lack of borders.

Applies to

See also