Language

ListBox.HorizontalScrollbar プロパティ

定義

水平スクロール バーがコントロールに表示されるかどうかを示す値を取得または設定します。

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 プロパティを設定する必要があります。

適用対象

こちらもご覧ください