ListBox.IntegralHeight Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy kontrolka powinna zmienić rozmiar, aby uniknąć wyświetlania częściowych elementów.

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

Wartość właściwości

true jeśli kontrolka zmienia rozmiar, tak aby nie wyświetlała częściowych elementów; w przeciwnym razie , false. Wartość domyślna to true.

Przykłady

Poniższy przykład kodu pokazuje, jak używać HorizontalScrollbar właściwości i HorizontalExtent do wyświetlania poziomego paska przewijania, który pokazuje cały tekst elementu w kontrolce ListBox . W przykładzie IntegralHeight użyto również właściwości , aby upewnić się, że elementy nie są częściowo wyświetlane z powodu rozmiaru kontrolki ListBox . Ten przykład wymaga dodania ListBox kontrolki o nazwie listBox1, do formularza.

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

Uwagi

Gdy ta właściwość jest ustawiona na true, kontrolka automatycznie zmienia rozmiar, aby upewnić się, że element nie jest częściowo wyświetlany. Jeśli chcesz zachować oryginalny rozmiar ListBox formularza na podstawie wymagań dotyczących miejsca w formularzu, ustaw tę właściwość na false.

Domyślnie rozmiary i CheckedListBox są takie, ListBox że wyświetlają tylko całe elementy. Jeśli chcesz, aby obszar ListBox zadokowany lub CheckedListBox został całkowicie wypełniony, ustaw wartość IntegralHeightfalse. Powoduje to całkowite wypełnienie obszaru kontrolką, ale ostatni element nie jest w pełni wyświetlany.

Jeśli element ListBox nie zawiera żadnych elementów, ta właściwość nie ma wpływu.

Uwaga

Wysokość całkowita jest oparta na wysokości ListBoxobiektu , a nie wysokości obszaru klienta. W związku z tym, gdy IntegralHeight właściwość jest ustawiona true, elementy mogą być nadal częściowo wyświetlane, jeśli są wyświetlane paski przewijania.

Uwaga

Jeśli właściwość jest ustawiona DrawMode na DrawMode.OwnerDrawVariable, ta właściwość nie ma wpływu.

Dotyczy

Zobacz też