ListBox.HorizontalExtent Egenskap

Definition

Hämtar eller anger bredden med vilken den vågräta rullningslisten för en ListBox kan rulla.

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

Egenskapsvärde

Bredden i bildpunkter som den vågräta rullningslisten kan rulla kontrollen. Standardvärdet är noll.

Exempel

Följande kodexempel visar hur du använder HorizontalScrollbar egenskaperna och HorizontalExtent för att visa en vågrät rullningslist som visar all objekttext i ListBox kontrollen. Exemplet använder IntegralHeight också egenskapen för att säkerställa att objekt inte visas delvis på grund av kontrollens ListBox storlek. Det här exemplet kräver att en ListBox kontroll med namnet listBox1, har lagts till i ett formulär.

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

Kommentarer

Den här egenskapen rapporterar bara ett användbart värde om egenskapen HorizontalScrollbar är inställd på true. Om bredden på är ListBox mindre än värdet för den här egenskapen, rullar den vågräta rullningslisten objekt i ListBox. Om bredden på ListBox är lika med eller större än det här värdet döljs den vågräta rullningslisten. Värdet för den här egenskapen uppdateras inte dynamiskt av ListBox. Den här egenskapen är användbar när objekten i ListBox är ägarskapade. Om ägarens ritade objekt ListBox till exempel är 200 bildpunkter breda, men ListBox är 60 bildpunkter breda, HorizontalExtent måste egenskapen anges till 200 för att rulla objektens högra kant till kontrollens synliga region.

Gäller för

Se även