ListBox.HorizontalExtent 속성

정의

ListBox의 가로 스크롤 막대로 스크롤할 수 있는 너비를 가져오거나 설정합니다.

public:
 property int HorizontalExtent { int get(); void set(int value); };
public int HorizontalExtent { get; set; }
member this.HorizontalExtent : int with get, set
Public Property HorizontalExtent As Integer

속성 값

Int32

가로 스크롤 막대로 컨트롤을 스크롤할 수 있는 너비(픽셀)입니다. 기본값은 0입니다.

예제

다음 코드 예제에서는 사용 하는 방법을 보여 줍니다 및 HorizontalExtent 컨트롤의 HorizontalScrollbar 모든 항목 텍스트를 ListBox 표시 하는 가로 스크롤 막대를 표시 하는 속성입니다. 또한 이 예제에서는 컨트롤의 ListBox 크기 때문에 항목이 부분적으로 표시되지 않도록 속성을 사용합니다IntegralHeight. 이 예제에서는 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 유용한 값을 보고합니다 true. 너비 ListBox 가 이 속성 값보다 작으면 가로 스크롤 막대에서 항목을 ListBox가로로 스크롤합니다. 너비 ListBox 가 이 값보다 크거나 같으면 가로 스크롤 막대가 숨겨집니다. 이 속성의 값은 .에 ListBox의해 동적으로 업데이트되지 않습니다. 이 속성은 소유자의 항목이 ListBox 그려지는 경우에 유용 합니다. 예를 들어 소유자가 그린 항목의 ListBox 너비가 200픽셀이지만 ListBox 너비가 60픽셀인 HorizontalExtent 경우 항목의 오른쪽 가장자리를 컨트롤의 표시되는 영역으로 스크롤하려면 속성을 200으로 설정해야 합니다.

적용 대상

추가 정보