我写一个L,把CANVAS改成PRINTER。CANVAS就行,wth是指打印的宽度!我这个是指换行而言
procedure tform1.printtext (str:string;wth:integer);
var row:integer;
TEXTWTH:REAL;
TEXTHGH:INTEGER;
GSHU:INTEGER;
I,J:INTEGER;
begin
TEXTWTH:=CANVAS.TextWidth(STR) /LENGTH(STR);
IF CANVAS.TEXTWIDTH(STR)<WTH then
begin
CANVAS.TextOut(100,100,STR);
EXIT;
end;
TEXTHGH:=CANVAS.TextHeight (STR)+2;
ROW:=ROUND(CANVAS.TextWidth(STR)/WTH+0.5);
GSHU:= ROUND(WTH / TEXTWTH-0.5);
FOR J:=1 TO ROWdo
begin
FOR I:=1 TO GSHUdo
begin
IF I+(J-1)*GSHU>LENGTH(STR) then
EXIT;
CANVAS.TEXTOUT(ROUND(I*TEXTHGH),100+(J-1)*TEXTHGH,STR[I+(J-1)*GSHU]);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
printtext('FASDFFASDFASDFASDFADSFDSAFASDFD',100);
end;