Partager via


ListBox.IntegralHeight Propriété

Définition

Obtient ou définit une valeur indiquant si le contrôle doit être redimensionné pour éviter d’afficher des éléments partiels.

public:
 property bool IntegralHeight { bool get(); void set(bool value); };
public bool IntegralHeight { get; set; }
member this.IntegralHeight : bool with get, set
Public Property IntegralHeight As Boolean

Valeur de propriété

true si le contrôle est redimensionné afin qu’il n’affiche pas d’éléments partiels ; sinon, false. La valeur par défaut est true.

Exemples

L’exemple de code suivant montre comment utiliser les HorizontalScrollbar propriétés et HorizontalExtent les propriétés pour afficher une barre de défilement horizontale qui affiche tout le texte de l’élément dans le ListBox contrôle. L’exemple utilise également la IntegralHeight propriété pour s’assurer que les éléments ne sont pas partiellement affichés en raison de la taille du ListBox contrôle. Cet exemple nécessite qu’un ListBox contrôle nommé listBox1ait été ajouté à un formulaire.

private:
   void DisplayHScroll()
   {
      // Make sure no items are displayed partially.
      listBox1->IntegralHeight = true;

      // Add items that are wide to the ListBox.
      for ( int x = 0; x < 10; x++ )
      {
         listBox1->Items->Add( String::Format( "Item {0} is a very large value that requires scroll bars", x ) );

      }

      // Display a horizontal scroll bar.
      listBox1->HorizontalScrollbar = true;

      // Create a Graphics object to use when determining the size of the largest item in the ListBox.
      Graphics^ g = listBox1->CreateGraphics();

      // Determine the size for HorizontalExtent using the MeasureString method using the last item in the list.
      int hzSize = (int)g->MeasureString( dynamic_cast<String^>(listBox1->Items[ listBox1->Items->Count - 1 ]), listBox1->Font ).Width;

      // Set the HorizontalExtent property.
      listBox1->HorizontalExtent = hzSize;
   }
private void DisplayHScroll()
{
   // Make sure no items are displayed partially.
   listBox1.IntegralHeight = true;

   // Add items that are wide to the ListBox.
   for (int x = 0; x < 10; x++)
   {
      listBox1.Items.Add("Item  " + x.ToString() + " is a very large value that requires scroll bars");
   }

   // Display a horizontal scroll bar.
   listBox1.HorizontalScrollbar = true;

   // Create a Graphics object to use when determining the size of the largest item in the ListBox.
   Graphics g = listBox1.CreateGraphics();

   // Determine the size for HorizontalExtent using the MeasureString method using the last item in the list.
   int hzSize = (int) g.MeasureString(listBox1.Items[listBox1.Items.Count -1].ToString(),listBox1.Font).Width;
   // Set the HorizontalExtent property.
   listBox1.HorizontalExtent = hzSize;
}
Private Sub DisplayHScroll()
     ' Make sure no items are displayed partially.
   listBox1.IntegralHeight = True
   Dim x As Integer

   ' Add items that are wide to the ListBox.
   For x = 0 To 10
      listBox1.Items.Add("Item  " + x.ToString() + " is a very large value that requires scroll bars")
   Next x

   ' Display a horizontal scroll bar.
   listBox1.HorizontalScrollbar = True

   ' Create a Graphics object to use when determining the size of the largest item in the ListBox.
   Dim g As System.Drawing.Graphics = listBox1.CreateGraphics()


   ' Determine the size for HorizontalExtent using the MeasureString method using the last item in the list.
   Dim hzSize As Integer = g.MeasureString(listBox1.Items(listBox1.Items.Count - 1).ToString(), listBox1.Font).Width
   ' Set the HorizontalExtent property.
   listBox1.HorizontalExtent = hzSize
End Sub

Remarques

Lorsque cette propriété est définie truesur , le contrôle se redimensionne automatiquement pour s’assurer qu’un élément n’est pas partiellement affiché. Si vous souhaitez conserver la taille d’origine de l’espace ListBox requis par votre formulaire, définissez cette propriété falsesur .

Par défaut, les ListBox tailles et les CheckedListBox tailles sont telles qu’elles affichent uniquement des éléments entiers. Si vous souhaitez ListBoxCheckedListBox remplir ou remplir complètement une zone ancrée, définissez sur falseIntegralHeight . Cela entraîne l’affichage complet du contrôle dans la zone, mais le dernier élément n’est pas entièrement affiché.

Si la ListBox propriété ne contient aucun élément, cette propriété n’a aucun effet.

Note

La hauteur intégrale est basée sur la hauteur du ListBox, plutôt que sur la hauteur de la zone cliente. Par conséquent, lorsque la IntegralHeight propriété est définie true, les éléments peuvent toujours être partiellement affichés si des barres de défilement sont affichées.

Note

Si la DrawMode propriété est définie DrawMode.OwnerDrawVariablesur , cette propriété n’a aucun effet.

S’applique à

Voir aussi