ListBox.IntegralHeight Propriedade

Definição

Recebe ou define um valor que indica se o controlo deve redimensionar para evitar mostrar itens parciais.

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

Valor de Propriedade

true se o controlo for ajustado para não mostrar itens parciais; caso contrário, false. A predefinição é true.

Exemplos

O exemplo de código seguinte demonstra como usar as HorizontalScrollbar propriedades e HorizontalExtent para mostrar uma barra de deslocamento horizontal que mostra todo o texto dos itens no ListBox controlo. O exemplo também utiliza a IntegralHeight propriedade para garantir que os itens não são parcialmente exibidos devido ao tamanho do ListBox controlo. Este exemplo exige que um ListBox controlo, chamado listBox1, tenha sido adicionado a uma forma.

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

Observações

Quando esta propriedade é definida para true, o controlo redimensiona-se automaticamente para garantir que um item não é parcialmente exibido. Se quiser manter o tamanho original do ListBox com base nos requisitos de espaço do seu formulário, defina esta propriedade para false.

Por defeito, os ListBox tamanhos e CheckedListBox são tais que mostram apenas itens inteiros. Se quiseres que o ListBox ou CheckedListBox preencha completamente uma área acoplada, define IntegralHeight para false. Isto faz com que o controlo preencha completamente a área, mas o último item não é totalmente exibido.

Se não ListBox contiver itens, esta propriedade não tem efeito.

Note

A altura integral baseia-se na altura do ListBox, em vez da altura da área do cliente. Como resultado, quando a IntegralHeight propriedade está definida true, os itens ainda podem ser parcialmente mostrados se forem exibidas barras de deslocamento.

Note

Se a DrawMode propriedade for definida para DrawMode.OwnerDrawVariable, esta propriedade não tem efeito.

Aplica-se a

Ver também