ListBox.PreferredHeight Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient la hauteur combinée de tous les éléments dans le 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 combinée, en pixels, de tous les éléments du contrôle.
- Attributs
Exemples
L’exemple de code suivant montre comment définir la Size propriété d’une ListBox base sur la valeur de la PreferredHeight propriété afin d’afficher tous les éléments dans l’ensemble ListBox des éléments sans utiliser de barres de défilement. Cet exemple nécessite qu’un ListBox contrôle nommé listBox1ait é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 la ListBox taille doit être dimensionnée, afin d’afficher tous les éléments disponibles dans la liste et d’éviter d’afficher les barres de défilement verticales. Si la quantité d’éléments dans la ListBox taille est importante, le dimensionnement du contrôle à l’aide de la valeur de la PreferredHeight propriété peut entraîner la ListBox taille de la taille en dehors de la zone cliente du formulaire ou du ListBox conteneur.