ListBox.HorizontalScrollbar Eigenschaft
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Dient zum Abrufen oder Festlegen eines Werts, der angibt, ob eine horizontale Bildlaufleiste im Steuerelement angezeigt wird.
public:
property bool HorizontalScrollbar { bool get(); void set(bool value); };
public bool HorizontalScrollbar { get; set; }
member this.HorizontalScrollbar : bool with get, set
Public Property HorizontalScrollbar As Boolean
Eigenschaftswert
trueum eine horizontale Bildlaufleiste im Steuerelement anzuzeigen; andernfalls . false Der Standardwert lautet false.
Beispiele
Im folgenden Codebeispiel wird veranschaulicht, wie Sie mit den HorizontalScrollbar Eigenschaften HorizontalExtent eine horizontale Bildlaufleiste anzeigen, die ListBox den gesamten Elementtext im Steuerelement anzeigt. Das Beispiel verwendet auch die IntegralHeight Eigenschaft, um sicherzustellen, dass Elemente aufgrund der Größe des ListBox Steuerelements nicht teilweise angezeigt werden. Dieses Beispiel erfordert, dass einem Formular ein ListBox Steuerelement mit dem Namen listBox1hinzugefügt wurde.
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
Hinweise
Die HorizontalScrollbar Eigenschaft bestimmt, ob die ListBox horizontale Bildlaufleiste angezeigt werden soll, wenn die Breite der Elemente innerhalb des ListBox Steuerelements über den rechten Rand des Steuerelements hinausgeht. Wenn diese Eigenschaft auf true festgelegt ist, wird die Bildlaufleiste basierend auf der Breite der Elemente automatisch ListBoxangezeigt. Wenn es ListBox sich um ein besitzergezeichnetes ListBoxObjekt handelt, um eine horizontale Bildlaufleiste ordnungsgemäß anzuzeigen, müssen Sie die HorizontalExtent Eigenschaft festlegen.