Board index » delphi » Setting TListBox Width to Width of Widest String

Setting TListBox Width to Width of Widest String

I am using a list box to 'popup' as a menu in an address book app.

I would like to set its width to the display width of the longest
string. I have a routine to grab the longest string. Can anybody
advise me on how to use the length of this string, presumably coupled
with its font, to end up with a sensible width for the ListBox?

Many thanks.

--
Jeff Gaines Damerham Hampshire UK
j...@jgaines.co.uk

 

Re:Setting TListBox Width to Width of Widest String


Quote
Jeff Gaines wrote:

> I am using a list box to 'popup' as a menu in an address book app.

> I would like to set its width to the display width of the longest
> string. I have a routine to grab the longest string. Can anybody
> advise me on how to use the length of this string, presumably coupled
> with its font, to end up with a sensible width for the ListBox?

Hi Jeff,

Try ListBox.Canvas.TextWidth(MyLongestString);

Regards,
Scott

Re:Setting TListBox Width to Width of Widest String


On 1 Feb 2003 14:17:57 -0800, "Scott Maskiel"

Quote
<scott_mask...@{*word*81}junkmail.nemmco.com.au> wrote:
>Jeff Gaines wrote:

>> I am using a list box to 'popup' as a menu in an address book app.

>> I would like to set its width to the display width of the longest
>> string. I have a routine to grab the longest string. Can anybody
>> advise me on how to use the length of this string, presumably coupled
>> with its font, to end up with a sensible width for the ListBox?

>Hi Jeff,

>Try ListBox.Canvas.TextWidth(MyLongestString);

>Regards,
>Scott

Scott

Many thanks, that does the trick!

--
Jeff Gaines Damerham Hampshire UK
j...@jgaines.co.uk

Other Threads