Hi All,
How do I get the width and heigth of a given string using a given font ?
Currently I'm using:
with SomeObject do {SomeObject currently is of type TLabel}
begin
font.name := "Arial";
font.size := 10;
font.style := [fsBold];
Caption := S;
StringHeight := Canvas.TextHeight(S);
StringWidth := Canvas.TextWidth(S);
Width := StringWidth + 5;
Height := StringHeight + 5;
....
end;
{Delphi 1 code}
{All this in the Form's OnShow event}
However, this will give a wrong result, if SomeObject has not actually been
drawn yet with the applied Font. So, the first time I do SomeObject.Show,
the results are different from subsequent times.
However, I need to know get the right numbers before I do the actual
drawing in the applied Font, so I can calculate the size that SomeObject
will have to be ... (get my drift ??).
Anyone got some ideas ??
Hope to hear from you.
Bart.
--------------------------------------
Bart Broersma
broersma@knmg.nl
* Wave Rider 1.20 [NR] *
... UNREGISTERED EVALUATION COPY
--- Wave Rider v1.20
---------------
* Origin: Aargh! BBS Amsterdam (2:280/606)
|