BCB: how to get the (approximate) width of a character in a given TFont?

Posted by mawg on Stack Overflow See other posts from Stack Overflow or by mawg
Published on 2010-03-08T03:23:15Z Indexed on 2010/03/09 2:06 UTC
Read the original article Hit count: 225

Filed under:

It's a TMemo, not that that should make any difference.

Googling suggests that I can use Canvas->TextWidth() but those are Delphi examples and BCB doesn't seem to offer this property.

I really want something analogous to memo->Font->Height for width.

I realize that not all fonts are fixed width, so a good estimate will do.

All that I need is to take the width of a TMemo in pixels and make a reasonable guess at how many characters of the current font it will hold.


Of course, if I really want to be lazy, I can just google for the average height/width ratio, since height is known. Remember, an approximation is good enough for me if it is tricky to get exact.

http://www.plainlanguagenetwork.org/type/utbo211.htm says, " A width to height ratio of 3:5 (0.6) is recommended for most applications"

© Stack Overflow or respective owner

Related posts about c++builder