次の方法で共有


ListBox.IntegralHeight プロパティ

一部の項目しか表示されない状況を避けるために、コントロールのサイズを変更するかどうかを示す値を取得または設定します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

構文

'宣言
<LocalizableAttribute(True)> _
Public Property IntegralHeight As Boolean
'使用
Dim instance As ListBox
Dim value As Boolean

value = instance.IntegralHeight

instance.IntegralHeight = value
[LocalizableAttribute(true)] 
public bool IntegralHeight { get; set; }
[LocalizableAttribute(true)] 
public:
property bool IntegralHeight {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_IntegralHeight ()

/** @property */
public void set_IntegralHeight (boolean value)
public function get IntegralHeight () : boolean

public function set IntegralHeight (value : boolean)

プロパティ値

一部の項目しか表示されない状況を避けるためにコントロールのサイズを変更する場合は true。それ以外の場合は false。既定値は true です。

解説

このプロパティを true に設定すると、コントロールのサイズが自動的に変更されるため、項目が部分的にしか表示されないという状況は発生しなくなります。フォームのサイズ要件を基にして ListBox の元のサイズを維持する場合は、このプロパティを false に設定します。

既定では、ListBox および CheckedListBox は、項目全体だけを表示できるサイズに設定されます。ListBox または CheckedListBox をドッキングされた領域全体に表示する場合は、IntegralHeightfalse に設定します。これにより、コントロールが領域全体に表示されますが、最後の項目の一部は表示されません。

ListBox 内に項目がない場合、このプロパティは無効です。

注意

高さはクライアント領域の高さではなく ListBox の高さに基づきます。結果として、IntegralHeight プロパティが true に設定されている場合は、スクロール バーが表示されているときに項目が部分的にしか表示されないという状況が引き続き発生します。

注意

DrawMode プロパティが DrawMode.OwnerDrawVariable に設定されている場合は、このプロパティは無効です。

使用例

HorizontalScrollbar プロパティと HorizontalExtent プロパティを使用して、ListBox コントロールのすべての項目のテキストを表示するための水平スクロール バーを表示する方法を次のコード例に示します。また、この例では、IntegralHeight プロパティを使用して、ListBox コントロールのサイズにかかわらず、項目の全部が表示されることを保証します。この例では、listBox1 という名前の ListBox コントロールがフォームに追加されている必要があります。

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 名前空間
ListBox.DrawMode プロパティ