ListBox.PreferredHeight Propriété

Définition

Obtient la hauteur groupée de tous les éléments dans ListBox.

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

Valeur de propriété

Hauteur cumulée en pixels de tous les éléments dans le contrôle.

Attributs

Exemples

L’exemple de code suivant montre comment définir la Size propriété d’un ListBox en fonction de la valeur de la PreferredHeight propriété afin d’afficher tous les éléments du ListBox sans utiliser de barres de défilement. Cet exemple nécessite qu’un ListBox contrôle, nommé listBox1, ait été ajouté à un formulaire.

private:
   void SizeMyListBox()
   {
      // Add items to the ListBox.
      for ( int x = 0; x < 20; x++ )
      {
         listBox1->Items->Add( String::Format( "Item {0}", x ) );
      }
      listBox1->Height = listBox1->PreferredHeight;
   }
private void SizeMyListBox()
{
   // Add items to the ListBox.
   for(int x = 0; x < 20; x++)
   {
      listBox1.Items.Add("Item " + x.ToString());
   }
   // Set the height of the ListBox to the preferred height to display all items.
   listBox1.Height = listBox1.PreferredHeight;
}
Private Sub SizeMyListBox()
   ' Add items to the ListBox.
   Dim x As Integer
   For x = 0 To 19
      listBox1.Items.Add(("Item " + x.ToString()))
   Next x
   ' Set the height of the ListBox to the preferred height to display all items.
   listBox1.Height = listBox1.PreferredHeight
End Sub

Remarques

Cette propriété vous permet de déterminer la hauteur à laquelle le ListBox doit être dimensionné, afin d’afficher chaque élément disponible dans la liste et d’éviter d’afficher des barres de défilement verticales. Si la quantité d’éléments dans le ListBox est importante, le dimensionnement du contrôle à l’aide de la valeur de la PreferredHeight propriété peut entraîner une ListBox dimensionnement en dehors de la zone cliente du formulaire ou du ListBox conteneur.

S’applique à

Voir aussi