ListBox.IntegralHeight 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示控件是否应调整大小以避免只显示项的局部。
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 或 完全填充停靠区域,请将 设置为 falseIntegralHeight 。CheckedListBox 这会导致控件完全填充区域,但最后一项未完全显示。
ListBox如果 不包含任何项,则此属性无效。
注意
整型高度基于 的高度 ListBox,而不是工作区高度。 因此,当设置 true属性时IntegralHeight,如果显示滚动条,仍可以部分显示项。
注意
              DrawMode如果该属性设置为 DrawMode.OwnerDrawVariable,则此属性无效。