ListBox.IntegralHeight Propriedade

Definição

Obtém ou define um valor que indica se o controle deve ser redimensionado para evitar a exibição de 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 da propriedade

Boolean

true se o controle for redimensionado para não exibir itens parciais; caso contrário, false. O padrão é true.

Exemplos

O exemplo de código a seguir demonstra como usar e propriedades HorizontalScrollbar HorizontalExtent para exibir uma barra de rolagem horizontal que mostra todo o texto do ListBox item no controle. O exemplo também usa a IntegralHeight propriedade para garantir que os itens não sejam exibidos parcialmente devido ao tamanho do ListBox controle. Este exemplo exige que um ListBox controle, nomeado listBox1, tenha sido adicionado a um formulário.

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

Comentários

Quando essa propriedade é definida como true, o controle redimensiona automaticamente para garantir que um item não seja exibido parcialmente. Se você quiser manter o tamanho original do ListBox com base nos requisitos de espaço do formulário, defina essa propriedade como false.

Por padrão, e ListBox os CheckedListBox tamanhos são tais que eles mostram apenas itens inteiros. Se você quiser ListBox CheckedListBox ou preencher completamente uma área encaixada, defina IntegralHeight como false. Isso faz com que o controle preencha completamente a área, mas o último item não é totalmente exibido.

Se a ListBox propriedade não contiver nenhum item, essa propriedade não terá efeito.

Observação

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

Observação

Se a DrawMode propriedade estiver definida como DrawMode.OwnerDrawVariable, essa propriedade não terá efeito.

Aplica-se a

Confira também