Board index » delphi » ListBox.TextWidth doesn't seem to get the right value
Michael D. Spence
![]() Delphi Developer |
Sun, 18 Feb 2001 03:00:00 GMT
|
Michael D. Spence
![]() Delphi Developer |
Sun, 18 Feb 2001 03:00:00 GMT
ListBox.TextWidth doesn't seem to get the right value
I want to make the width of a listbox the same as that of its longest
string. Scanning through the items, I find that the longest is the i-th element, then do this: Listbox.Width := Listbox.Canvas.TextWidth(Listbox.Items [i]); The last few characters get clipped. If I add some extra space so that Listbox.Width := Listbox.Canvas.TextWidth(Listbox.Items [i]) + things are better, but a long enough string will still get clipped. The -- |
Kurt Barthelmess (Tea
![]() Delphi Developer |
Mon, 19 Feb 2001 03:00:00 GMT
Re:ListBox.TextWidth doesn't seem to get the right valueMichael - > Are there some Yes. There are things called "borders". And there's also some internal Good luck. Kurt |
Team
![]() Delphi Developer |
Mon, 19 Feb 2001 03:00:00 GMT
Re:ListBox.TextWidth doesn't seem to get the right valueMichael: You have to make sure that the Canvas' Font is the same as the Listbox's. Then procedure TForm1.FormShow(Sender: TObject); with ListBox1 do begin Width := maxWidth -- Michael D. Spence < <@panix.com>> wrote in message |
Mark Horridg
![]() Delphi Developer |
Mon, 19 Feb 2001 03:00:00 GMT
Re:ListBox.TextWidth doesn't seem to get the right valueQuoteRalph Friedman (TeamB) wrote: - and scrolled through the newsgroup to console myself. And there I noticed the answer. Obviously, the Font of the ListBox and the Font of its Canvas are as similar Mark Horridge Quote> for i := 0 to Items.Count - 1 do begin Mark Horridge Centre of Policy Studies, Clayton Campus, Monash University, AUSTRALIA VIC 3168 email mark.horri...@buseco.monash.edu.au |
Michael D. Spenc
![]() Delphi Developer |
Mon, 19 Feb 2001 03:00:00 GMT
Re:ListBox.TextWidth doesn't seem to get the right valueQuoteMark Horridge wrote in message <35EE6C6A.4B541...@buseco.monash.edu.au>... Quote
is what I was really looking for. BUT: I wrote a program last night that let me change the font and that Anyway, thanks everybody. Quote
|
Michael D. Spenc
![]() Delphi Developer |
Mon, 19 Feb 2001 03:00:00 GMT
Re:ListBox.TextWidth doesn't seem to get the right valueMichael D. Spence < <@panix.com>> wrote in message Quote
Quote>returns pixels and ListBox.Width is a pixels dimension. gets changed. You have to keep them in sync yourself. Not sure why I thought it'd be different... Quote>Anyway, thanks everybody. - Hide quoted text - - Show quoted text - Quote
|
1. Why is it that SVGA doesn't seem to work in TP for me
2. MAKE doesn't seem to work on .bpg files from the command line
3. BUG: halt() doesn't seem to work
4. Yield doesn't seem to work in Delphi on Win95
5. Insert Doesn't seem to do Anything
6. hidden window doesn't seem to recieve message
7. DDE SetLink doesn't seem to like full paths
8. D4 TDBGrid scroll button doesn't seem to move correctly
9. TWebBrowser.eBeforeNavigate2 Doesn't Seem to Redirect URL