ListBox.PreferredHeight プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


このプロパティを使用すると、利用できるすべての項目をリストに表示し、垂直スクロール バーを表示しないようにするために、ListBox に必要とされる高さを確認できます。ListBox 内の項目数が多い場合に、PreferredHeight プロパティの値を使用してコントロールのサイズを設定すると、ListBox が、フォームや ListBox のコンテナのクライアント領域の外にはみ出すサイズになる可能性があります。

ListBox のすべての項目をスクロール バーを使用せずに表示する目的で、PreferredHeight プロパティの値に基づいて ListBox の Size プロパティを設定する方法を次のコード例に示します。この例では、listBox1 という名前の ListBox コントロールがフォームに追加されている必要があります。
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 'SizeMyListBox
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: 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.get_Items().Add("Item " + Convert.ToString(x)); } // Set the height of the ListBox to the preferred height // to display all items. listBox1.set_Height(listBox1.get_PreferredHeight()); } //SizeMyListBox

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からListBox.PreferredHeight プロパティを検索する場合は、下記のリンクをクリックしてください。

- ListBox.PreferredHeight プロパティのページへのリンク