TIP: Click on subject to list as thread! ANSI
echo: delphi
to: BART BROERSMA
from: KONSTANTIN SUSLOV
date: 1997-04-22 09:06:00
subject: Re: Width of a string in pixels.

Hello Bart!
Пон Апp 21 1997 00:31, Bart Broersma wrote to All:
 BB> How do I get the width and heigth of a given string using a given font
 BB> ? Currently I'm using:
 BB>   with SomeObject do        {SomeObject currently is of type TLabel}
 BB>   begin
 BB>     font.name := "Arial";
 BB>     font.size := 10;
 BB>     font.style := [fsBold];
 BB>     Caption := S;
 BB>     StringHeight := Canvas.TextHeight(S);
 BB>     StringWidth := Canvas.TextWidth(S);
 BB>     Width := StringWidth + 5;
 BB>     Height := StringHeight + 5;
 BB>     ....
 BB>   end;
 BB> {Delphi 1 code}
 BB> Anyone got some ideas ??
 For example, for width of TLabel may be use follow function:
function GetWidth_Label(ED:HFont):integer;
var systemmetric,metric:ttextmetric; DC:HDC;SaveFont:HFont; i:integer;
begin
Dc:=GetDc(0);
GetTextMetrics(dc,SystemMetric);
SaveFont:=SelectObject(Dc,ED);
GetTextMetrics(dc,Metric);
SelectObject(Dc,SaveFont);
ReleaseDc(0,dc);
Result:=
Metric.tmAveCharWidth{+systemMetric.tmAveCharWidth div 8}+
GetSystemMetrics(SM_CXBORDER)*2;
end;
Best Regards, KS
---
---------------
* Origin: Moscow, Zelenograd (2:5020/300.16)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.