获取指定字符的宽度
方法一:
var
CharX, CharY: Integer;
with Canvas do
begin
Font.Name := '宋体';
Size := 9;
CharX := TextExtent('字符串').cx; //字符串宽度,单位为像素
CharY := TextExtent('字符串').cy; //字符高度,单位为像素
end;
方法二:
var
s: TSize;
with Canvas do
begin
Font.Name := '宋体';
Size := 9;
s := TextExtent('字符串');
ShowMessage(Format('字宽:%d 字高:%d', [s.cx, s.cy]);
end;