ListBox.HorizontalScrollbar 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,指出選取水平捲軸是否顯示於控制項中。
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
屬性值
如果水平捲軸顯示於控制項中,則為 true
,否則為 false
。 預設為 false
。
範例
下列程式碼範例示範如何使用 HorizontalScrollbar 和 HorizontalExtent 屬性來顯示水準捲軸,以顯示控制項中的所有 ListBox 專案文字。 此範例也會使用 IntegralHeight 屬性來確保專案不會部分顯示,因為控制項的大小 ListBox 。 此範例要求 ListBox 已將名為 的 listBox1
控制項新增至表單。
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
備註
屬性 HorizontalScrollbar 會決定 在超出控制項右邊緣的專案 ListBox 寬度時,是否 ListBox 應該顯示水準捲軸。 當此屬性設定為 true
時,系統會根據 中的 ListBox 專案寬度自動顯示捲軸。
ListBox如果 是擁有者繪製 ListBox 的 ,若要正確顯示水準捲軸,您必須設定 HorizontalExtent 屬性。