Fórum ComboBox DUVIDA CRUEL! #190642
24/10/2003
0
Até aí tudo bem. O problema é que os textos que estão os [i:ce00bde5f0]Items[/i:ce00bde5f0] são maiores que este tamanho.
[b:ce00bde5f0]Como faço para aumentar a largura da lista de DropDown do Combobox?[/b:ce00bde5f0]
Obrigado,
Tenil
Curtir tópico
+ 0Posts
24/10/2003
Beppe
procedure TForm1.ComboBox1DropDown(Sender: TObject); var I, MaxWidth, OneWidth: Integer; begin with (Sender as TCustomComboBox) do begin MaxWidth := Width; for I := 0 to Items.Count - 1 do begin OneWidth := Canvas.TextWidth(Items[I]); if OneWidth > MaxWidth then MaxWidth := OneWidth; end; SendMessage(Handle, CB_SETDROPPEDWIDTH, MaxWidth + 8, 0); end; end;
Ataliba
Gostei + 0
24/10/2003
Tenil
Se não for pedir demais, você poderia me dar uma breve explicação deste código?
Gostei + 0
24/10/2003
Beppe
Brincadeira. Agora, comentado:
procedure TForm1.ComboBox1DropDown(Sender: TObject); var MaxWidth: Integer; // largura do maior item OneWidth: Integer; // largura do item corrente I: Integer; // sei lah... begin // pra simplificar o acesso, e garantir que estamos // trabalhando com um combo with (Sender as TCustomComboBox) do begin // assume que a maior largura é a largura da combo MaxWidth := Width; // verifica cada item for I := 0 to Items.Count - 1 do begin // pega a largura deste OneWidth := Canvas.TextWidth(Items[I]); // se é maior que a atual, muda... if OneWidth > MaxWidth then MaxWidth := OneWidth; end; // manda uma mensagem para alterar a largura da // listbox(eh uma listbox que eh aberta), com uma folga de 8 SendMessage(Handle, CB_SETDROPPEDWIDTH, MaxWidth + 8, 0); end; end;
E eh isso...
Ataliba
Gostei + 0
24/10/2003
Tenil
Eheheh
Valeu mano, abraço.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)