Label.PreferredHeight Propriedade

Definição

Obtém a altura preferencial do controle.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

Valor da propriedade

A altura do controle (em pixels), supondo que uma única linha de texto é exibida.The height of the control (in pixels), assuming a single line of text is displayed.

Atributos

Exemplos

O exemplo de código a seguir demonstra como criar um controle de Label que tem uma borda tridimensional e uma imagem exibida usando as propriedades ImageList e ImageIndex.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. O controle também tem uma legenda com um caractere mnemônico especificado.The control also has a caption with a mnemonic character specified. O código de exemplo usa as propriedades PreferredHeight e PreferredWidth para dimensionar corretamente o controle de Label no formulário no qual ele é exibido.The example code uses the PreferredHeight and PreferredWidth properties to properly size the Label control on the form on which it is displayed. Este exemplo requer que um ImageList tenha sido criado e nomeado imageList1 e que tenha carregado duas imagens.This example requires that an ImageList has been created and named imageList1 and that it has loaded two images. O exemplo também exige que o código esteja dentro de um formulário que tenha o namespace System.Drawing adicionado ao seu código.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

Comentários

Essa propriedade retorna a altura que o controle deve estar para exibir corretamente o texto, com base na fonte atribuída ao controle.This property returns the height that the control should be in order to properly display text, based on the font assigned to the control. Você pode usar essa propriedade junto com a propriedade PreferredWidth para garantir que o texto no controle de Label seja exibido corretamente.You can use this property along with the PreferredWidth property to ensure that the text in the Label control is displayed properly. Você pode usar a propriedade AutoSize para ajustar automaticamente a altura e a largura do controle de Label, com base no tamanho do texto e da fonte.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.

Observação

Se a propriedade BorderStyle do controle de Label for definida como BorderStyle.None, o valor retornado pela propriedade PreferredHeight será maior devido à falta de bordas.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.

Aplica-se a

Veja também