您的位置:首页 > 编程语言 > Delphi

Delphi 图形处理 技巧

2006-05-16 08:57 411 查看

1。得到输出字符串在 屏幕上的象素数。

BOOL GetTextExtentPoint32(    HDC hdc, // handle of device context
LPCTSTR lpString, // address of text string
int cbString, // number of characters in string
LPSIZE lpSize  // address of structure for string size
);

利用该函数 我们可以得到 字符串在屏幕上的 象素数。

应用举例:使不同长度字符串 输出时 右 对齐。

var
Str:String;
sizeFont:Size;
ndata:integer;
begin
str:='13456';
with Image1.Canvas do
begin
GetTextExtentPoint32(Image1.Canvas.Handle, PChar(str), Length(str), sizeFont);
TextOut(100 - sizeFont.cx,10,str);
str:='13456789';
GetTextExtentPoint32(Image1.Canvas.Handle, PChar(str), Length(str), sizeFont);
TextOut(100 - sizeFont.cx,30,str);
ndata:=-13456;
str:=Inttostr(ndata);
GetTextExtentPoint32(Image1.Canvas.Handle, PChar(str), Length(str), sizeFont);
TextOut(100 - sizeFont.cx,60,str);

end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: