就是想知道qrmemo, qrdbtext的高度吗?
so easy:
var
r: TRect;
tmpfont: TFont;
s: string;
begin
tmpfont := tfont.create;
tmpfont := printer.canvas.font;
printer.canvas.font := qrmemo1.font;
s := qrmemo1.lines.text;
r := rect(0, 0, qrmemo1.width, qrmemo1.height);
drawtext(printer.canvas.handle, pchar(s), length(s), r, DT_CALCRECT or DT_EXTERNALLEADING or DT_WORDBREAK);
printer.canvas.font := tmpfont;
tmpfont.free;
qrmemo1.width := r.right;
qrmemo1.height := r.bottom;
end;
如果qrmemo的wordwrap = false, 那稍微麻烦点.
不过一样思路, 只是r的初始化不同, r.right必须为最长行的长度(可以用
printer.canvas.textwidth(stringlist.strings)获得).