1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| function TextSize(Phrase:string;police:TFont=nil):TPoint;
var
DC: HDC;
X: Integer;
Rect: TRect;
C : TBitmap;
begin
C := TBitmap.create;
try
if police <> nil then C.canvas.Font := police;
Rect.Left := 0;
Rect.Top:=0;
Rect.Right:=0;
Rect.Bottom:=0;
DC := GetDC(0);
C.Canvas.Handle := DC;
DrawText(C.Canvas.Handle, PChar(Phrase), Length(Phrase), Rect, (DT_EXPANDTABS or DT_CALCRECT));
C.Canvas.Handle := 0;
ReleaseDC(0, DC);
result.X:=Rect.Right;
result.Y:=Rect.Bottom;
finally
C.Free;
end;
end; |