ListBox.HorizontalExtent Propriedade

Definição

Obtém ou define a largura pela qual a barra de rolagem horizontal de um ListBox pode rolar.

public:
 property int HorizontalExtent { int get(); void set(int value); };
public int HorizontalExtent { get; set; }
member this.HorizontalExtent : int with get, set
Public Property HorizontalExtent As Integer

Valor da propriedade

Int32

A largura, em pixels, até a qual a barra de rolagem horizontal pode rolar o controle. O padrão é zero.

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

Essa propriedade só relatará um valor útil se a HorizontalScrollbar propriedade estiver definida como true. Se a largura da ListBox propriedade for menor que o valor dessa propriedade, a barra de rolagem horizontal rolará horizontalmente os itens no ListBox. Se a largura do ListBox valor for igual ou maior que esse valor, a barra de rolagem horizontal ficará oculta. O valor dessa propriedade não é atualizado dinamicamente pelo ListBox. Essa propriedade é útil quando os itens do ListBox proprietário são desenhados pelo proprietário. Por exemplo, se o proprietário desenhou itens de ListBox 200 pixels de largura, mas o ListBox tem 60 pixels de largura, a HorizontalExtent propriedade precisaria ser definida como 200 para rolar a borda direita dos itens para a região visível do controle.

Aplica-se a

Confira também