Label.PreferredHeight Propiedad

Definición

Obtiene el alto preferido del control.Gets the preferred height of the control.

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

Valor de propiedad

Int32

Alto del control, en píxeles, suponiendo que se muestra una sola línea de texto.The height of the control (in pixels), assuming a single line of text is displayed.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo crear un Label control que tiene un borde tridimensional y una imagen que se muestra utilizando las ImageList ImageIndex propiedades y.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. El control también tiene un título con un carácter mnemotécnico especificado.The control also has a caption with a mnemonic character specified. El código de ejemplo utiliza PreferredHeight las PreferredWidth propiedades y para ajustar correctamente el tamaño del Label control en el formulario en el que se muestra.The example code uses the PreferredHeight and PreferredWidth properties to properly size the Label control on the form on which it is displayed. En este ejemplo se requiere que se haya ImageList creado y denominado imagelist1 y que haya cargado dos imágenes.This example requires that an ImageList has been created and named imageList1 and that it has loaded two images. En el ejemplo también se requiere que el código esté dentro de un formulario que tenga el System.Drawing espacio de nombres agregado a su 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

Comentarios

Esta propiedad devuelve el alto que debe tener el control para mostrar correctamente el texto, en función de la fuente asignada al control.This property returns the height that the control should be in order to properly display text, based on the font assigned to the control. Puede usar esta propiedad junto con la PreferredWidth propiedad para asegurarse de que el texto del Label control se muestre correctamente.You can use this property along with the PreferredWidth property to ensure that the text in the Label control is displayed properly. Puede utilizar la AutoSize propiedad para ajustar automáticamente el alto y el ancho del Label control, en función del tamaño del texto y de la fuente.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.

Nota

Si la BorderStyle propiedad del Label control se establece en BorderStyle.None , el valor devuelto por la PreferredHeight propiedad será mayor debido a la falta de bordes.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.

Se aplica a

Consulte también