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)
|