다음을 통해 공유


ListBox.HorizontalExtent 속성

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

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<LocalizableAttribute(True)> _
Public Property HorizontalExtent As Integer
‘사용 방법
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)

속성 값

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

설명

이 속성을 사용하면 HorizontalScrollbar 속성이 true로 설정된 경우 유용한 값만 보고됩니다. ListBox의 너비가 이 속성의 값보다 작으면 가로 스크롤 막대로 ListBox의 항목을 가로로 스크롤할 수 있습니다. ListBox의 너비가 이 값보다 크거나 같으면 가로 스크롤 막대가 숨겨집니다. 이 속성의 값은 ListBox에 의해 동적으로 업데이트되지 않습니다. 이 속성은 ListBox의 항목을 소유자가 그린 경우 유용합니다. 예를 들어, 소유자가 그린 ListBox 항목의 너비가 200픽셀이고 ListBox 너비가 60픽셀이면, 컨트롤의 볼 수 있는 영역으로 항목의 오른쪽 가장자리를 스크롤하기 위해 HorizontalExtent 속성을 200으로 설정해야 합니다.

예제

다음 코드 예제에서는 HorizontalScrollbarHorizontalExtent 속성을 사용하여 ListBox 컨트롤의 모든 항목 텍스트를 보여 주는 가로 스크롤 막대를 표시하는 방법을 보여 줍니다. 또한 다음 예제에서는 IntegralHeight 속성을 사용하여 ListBox 컨트롤의 크기로 인해 항목이 부분적으로 표시되지 않도록 하는 방법을 보여 줍니다. 이 예제를 실행하려면 이름이 listBox1ListBox 컨트롤이 폼에 추가되어 있어야 합니다.

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

플랫폼

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

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

ListBox 클래스
ListBox 멤버
System.Windows.Forms 네임스페이스
HorizontalScrollbar