Export (0) Print
Expand All
2 out of 3 rated this helpful - Rate this topic

ListBox.IntegralHeight Property

Gets or sets a value indicating whether the control should resize to avoid showing partial items.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
public bool IntegralHeight { get; set; }

Property Value

Type: System.Boolean
true if the control resizes so that it does not display partial items; otherwise, false. The default is true.

When this property is set to true, the control automatically resizes to ensure that an item is not partially displayed. If you want to maintain the original size of the ListBox based on the space requirements of your form, set this property to false.

By default, the ListBox and the CheckedListBox sizes are such that they show only whole items. If you want the ListBox or CheckedListBox to completely fill a docked area, set IntegralHeight to false. This causes the control to completely fill the area, but the last item is not fully displayed.

If the ListBox does not contain any items, this property has no effect.

NoteNote

The integral height is based on the height of the ListBox, rather than the client area height. As a result, when the IntegralHeight property is set true, items can still be partially shown if scroll bars are displayed.

NoteNote

If the DrawMode property is set to DrawMode.OwnerDrawVariable, this property has no effect.

The following code example demonstrates how to use the HorizontalScrollbar and HorizontalExtent properties to display a horizontal scroll bar that shows all item text in the ListBox control. The example also uses the IntegralHeight property to ensure that items are not partially displayed due to the size of the ListBox control. This example requires that a ListBox control, named listBox1, has been added to a form.

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;
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.