ListBox.HorizontalExtent Eigenschap

Definitie

Hiermee haalt u de breedte op waarmee de horizontale schuifbalk van een ListBox schuifbalk kan schuiven.

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

Waarde van eigenschap

De breedte, in pixels, dat de horizontale schuifbalk het besturingselement kan schuiven. De standaardwaarde is nul.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe u de HorizontalScrollbar en HorizontalExtent eigenschappen gebruikt om een horizontale schuifbalk weer te geven waarin alle itemtekst in het ListBox besturingselement wordt weergegeven. In het voorbeeld wordt ook de IntegralHeight eigenschap gebruikt om ervoor te zorgen dat items niet gedeeltelijk worden weergegeven vanwege de grootte van het ListBox besturingselement. Voor dit voorbeeld is vereist dat een ListBox besturingselement met de naam listBox1is toegevoegd aan een formulier.

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

Opmerkingen

Deze eigenschap rapporteert alleen een nuttige waarde als de HorizontalScrollbar eigenschap is ingesteld op true. Als de breedte van de ListBox eigenschap kleiner is dan de waarde van deze eigenschap, schuift de horizontale schuifbalk horizontaal door items in de ListBox. Als de breedte van de ListBox waarde gelijk is aan of groter is dan deze waarde, is de horizontale schuifbalk verborgen. De waarde van deze eigenschap wordt niet dynamisch bijgewerkt door de ListBox. Deze eigenschap is handig wanneer de items van de ListBox eigenaar zijn getekend. Als de eigenaar bijvoorbeeld items van ListBox 200 pixels breed heeft, maar de ListBox eigenschap 60 pixels breed is, moet de HorizontalExtent eigenschap worden ingesteld op 200 om de rechterrand van de items naar het zichtbare gebied van het besturingselement te schuiven.

Van toepassing op

Zie ook