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

範例

下列程式碼範例示範如何使用 HorizontalScrollbarHorizontalExtent 屬性來顯示顯示 控制項中 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

根據預設, ListBoxCheckedListBox 大小會讓它們只顯示整個專案。 如果您想要 ListBoxCheckedListBox 完全填滿停駐區域,請將 設定 IntegralHeightfalse 。 這會導致控制項完全填滿區域,但最後一個專案並未完全顯示。

ListBox如果 不包含任何專案,這個屬性就不會有任何作用。

注意

整數高度是以 的高度 ListBox 為基礎,而不是工作區高度。 因此,設定 屬性 trueIntegralHeight ,如果顯示捲軸,仍然可以部分顯示專案。

注意

如果屬性 DrawMode 設定為 DrawMode.OwnerDrawVariable ,這個屬性就不會有任何作用。

適用於

另請參閱