Freigeben über


ListBox.HorizontalExtent-Eigenschaft

Ruft die Breite ab, innerhalb der mit einer horizontalen Bildlaufleiste einer ListBox Bildläufe durchgeführt werden können, oder legt diese fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
<LocalizableAttribute(True)> _
Public Property HorizontalExtent As Integer
'Usage
Dim instance As ListBox
Dim value As Integer

value = instance.HorizontalExtent

instance.HorizontalExtent = value
[LocalizableAttribute(true)] 
public int HorizontalExtent { get; set; }
[LocalizableAttribute(true)] 
public:
property int HorizontalExtent {
    int get ();
    void set (int value);
}
/** @property */
public int get_HorizontalExtent ()

/** @property */
public void set_HorizontalExtent (int value)
public function get HorizontalExtent () : int

public function set HorizontalExtent (value : int)

Eigenschaftenwert

Die Breite in Pixel, innerhalb der mit der horizontalen Bildlaufleiste im Steuerelement Bildläufe durchgeführt werden können. Der Standardwert ist 0.

Hinweise

Diese Eigenschaft gibt nur dann einen sinnvollen Wert zurück, wenn die HorizontalScrollbar-Eigenschaft auf true festgelegt ist. Wenn die Breite von ListBox kleiner als der Wert dieser Eigenschaft ist, kann mit der horizontalen Bildlaufleiste ein horizontaler Bildlauf zu den Elementen in ListBox durchgeführt werden. Wenn die Breite von ListBox gleich diesem oder größer als dieser Wert ist, ist die horizontale Bildlaufleiste ausgeblendet. Der Wert dieser Eigenschaft wird von der ListBox nicht dynamisch aktualisiert. Diese Eigenschaft ist nützlich, wenn die Elemente von ListBox ownerdrawn sind. Wenn die Ownerdrawn-Elemente der ListBox z. B. 200 Pixel breit sind, ListBox jedoch nur 60 Pixel breit ist, muss die HorizontalExtent-Eigenschaft auf 200 festgelegt werden, damit der rechte Rand der Elemente über einen Bildlauf im sichtbaren Bereich des Steuerelements angezeigt werden kann.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie mithilfe der HorizontalScrollbar-Eigenschaft und der HorizontalExtent-Eigenschaft eine horizontale Bildlaufleiste angezeigt wird, mit der der gesamte Elementtext im ListBox-Steuerelement angezeigt werden kann. In diesem Beispiel wird mithilfe der IntegralHeight-Eigenschaft sichergestellt, dass Elemente aufgrund der Größe des ListBox-Steuerelements nicht abgeschnitten werden. Für dieses Beispiel muss dem Formular das ListBox-Steuerelement listBox1 hinzugefügt werden.

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
private void DisplayHScroll()
{
   // Make no partial items are displayed vertically.
   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:
   void DisplayHScroll()
   {
      // Make no partial items are displayed vertically.
      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 no partial items are displayed vertically.
    listBox1.set_IntegralHeight(true);

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

    // Display a horizontal scroll bar.
    listBox1.set_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.get_Items().
        get_Item(listBox1.get_Items().get_Count() - 1).ToString(), 
        listBox1.get_Font()).get_Width());

    // Set the HorizontalExtent property.
    listBox1.set_HorizontalExtent(hzSize);
} //DisplayHScroll

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

ListBox-Klasse
ListBox-Member
System.Windows.Forms-Namespace
HorizontalScrollbar