ListBox.HorizontalExtent 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 ou définit la largeur par laquelle la barre de défilement horizontale d’un ListBox peut faire défiler.
public:
property int HorizontalExtent { int get(); void set(int value); };
public int HorizontalExtent { get; set; }
member this.HorizontalExtent : int with get, set
Public Property HorizontalExtent As Integer
Valeur de propriété
Largeur, en pixels, que la barre de défilement horizontale peut faire défiler le contrôle. La valeur par défaut est zéro.
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
Cette propriété signale uniquement une valeur utile si la HorizontalScrollbar propriété est définie sur true. Si la largeur de la ListBox propriété est inférieure à la valeur de cette propriété, la barre de défilement horizontale fait défiler horizontalement les éléments dans le ListBox. Si la largeur de la ListBox valeur est égale ou supérieure à cette valeur, la barre de défilement horizontale est masquée. La valeur de cette propriété n’est pas mise à jour dynamiquement par le ListBox. Cette propriété est utile lorsque les éléments du ListBox fichier sont dessinés par le propriétaire. Par exemple, si les éléments dessinés par le propriétaire des éléments sont ListBox de 200 pixels de large, mais que la ListBox largeur est de 60 pixels, la HorizontalExtent propriété doit être définie sur 200 pour faire défiler le bord droit des éléments dans la région visible du contrôle.