Language

ListBox.IntegralHeight プロパティ

定義

部分的な項目が表示されないようにコントロールのサイズを変更するかどうかを示す値を取得または設定します。

public:
 property bool IntegralHeight { bool get(); void set(bool value); };
public bool IntegralHeight { get; set; }
member this.IntegralHeight : bool with get, set
Public Property IntegralHeight As Boolean

プロパティ値

true コントロールが部分的な項目を表示しないようにサイズを変更する場合。それ以外の場合は false。 既定値は true です。

例

次のコード例では、 HorizontalScrollbar プロパティと HorizontalExtent プロパティを使用して、 ListBox コントロール内のすべての項目テキストを表示する水平スクロール バーを表示する方法を示します。 この例では、 IntegralHeight プロパティを使用して、 ListBox コントロールのサイズが原因で項目が部分的に表示されないようにします。 この例では、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

注釈

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

既定では、 ListBox と CheckedListBox のサイズは、項目全体のみを表示します。 ListBoxまたはCheckedListBoxがドッキング領域を完全に塗りつぶす場合は、IntegralHeightをfalseに設定します。 これにより、コントロールは領域を完全に塗りつぶしますが、最後の項目は完全には表示されません。

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

Note

整数の高さは、クライアント領域の高さではなく、 ListBoxの高さに基づいています。 その結果、 IntegralHeight プロパティが true設定されている場合でも、スクロール バーが表示されている場合でも項目を部分的に表示できます。

Note

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

適用対象

こちらもご覧ください