Gets or sets the width by which the horizontal scroll bar of a ListBox can scroll.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
This property only reports a useful value if the HorizontalScrollbar property is set to true. If the width of the ListBox is smaller than the value of this property, the horizontal scroll bar horizontally scrolls items in the ListBox. If the width of the ListBox is equal to or greater than this value, the horizontal scroll bar is hidden. The value of this property is not dynamically updated by the ListBox. This property is useful when the items of the ListBox are owner-drawn. For example, if the owner drawn items of the ListBox are 200 pixels wide, but the ListBox is 60 pixels wide, the property would need to be set to 200 in order to scroll the right edge of the items into the visible region of the control.
The following code example demonstrates how to use the HorizontalScrollbar and properties to display a horizontal scroll bar that shows all item text in the ListBox control. The example also uses the IntegralHeight property to ensure that items are not partially displayed due to the size of the ListBox control. This example requires that a ListBox control, named listBox1, has been added to a form.
Private Sub DisplayHScroll() ' Make no partial items are displayed vertically. 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