ListBox.PreferredHeight 속성

정의

ListBox에 있는 모든 항목의 전체 높이를 가져옵니다.

public:
 property int PreferredHeight { int get(); };
[System.ComponentModel.Browsable(false)]
public int PreferredHeight { get; }
[<System.ComponentModel.Browsable(false)>]
member this.PreferredHeight : int
Public ReadOnly Property PreferredHeight As Integer

속성 값

Int32

컨트롤에 있는 항목의 높이를 합하여 픽셀로 나타낸 것입니다.

특성

예제

다음 코드 예제에서는 스크롤 막대를 사용하지 않고 모든 항목을 ListBox 표시하기 위해 속성 값 PreferredHeight 에 따라 속성을 설정하는 Size ListBox 방법을 보여 줍니다. 이 예제에서는 명명listBox1ListBox 컨트롤이 양식에 추가되어야 합니다.

private:
   void SizeMyListBox()
   {
      // Add items to the ListBox.
      for ( int x = 0; x < 20; x++ )
      {
         listBox1->Items->Add( String::Format( "Item {0}", x ) );
      }
      listBox1->Height = listBox1->PreferredHeight;
   }
private void SizeMyListBox()
{
   // Add items to the ListBox.
   for(int x = 0; x < 20; x++)
   {
      listBox1.Items.Add("Item " + x.ToString());
   }
   // Set the height of the ListBox to the preferred height to display all items.
   listBox1.Height = listBox1.PreferredHeight;
}
Private Sub SizeMyListBox()
   ' Add items to the ListBox.
   Dim x As Integer
   For x = 0 To 19
      listBox1.Items.Add(("Item " + x.ToString()))
   Next x
   ' Set the height of the ListBox to the preferred height to display all items.
   listBox1.Height = listBox1.PreferredHeight
End Sub

설명

이 속성을 사용하면 목록에 사용 가능한 모든 항목을 표시하고 세로 스크롤 막대가 표시되지 않도록 크기를 조정해야 하는 높이 ListBox 를 결정할 수 있습니다. 항목 ListBox 의 양이 크면 속성 값을 사용하여 컨트롤의 크기를 조정하면 폼 또는 ListBox 컨테이너의 PreferredHeight 클라이언트 영역 외부에 크기가 지정될 수 있습니다ListBox.

적용 대상

추가 정보