MyMetaFile:TMetaFile;
pCanvas:TMetafileCanvas;
MyMetafile := TMetafile.Create;
MyMetaFile.Width:=PaintBox1.Width;
MyMetaFile.Height:=PaintBox1.Height;
MyMetaFile.Transparent:=true;
MyMetafile.Enhanced:=true;
pCanvas:= TMetafileCanvas.Create(MyMetafile, 0);
with pCanvas do
try
Pen.Style:=psSolid;//psdot;
Pen.Width:=1;
Pen.Color:=clGreen;
MoveTo(10,20);
LineTo(100,200);//Pixels[30,40]:=clRed;
TextOut(40,60,'Hello');
finally
Free;
end;
PaintBox1.Canvas.Draw(0,0,MyMetafile);
以上是显示
一下是打印
procedure TForm1.PrintFigButton1Click(Sender: TObject);
var
PrintHeight,PrintWidth:double;
begin
Printer.BeginDoc;
if(bStretch)then//bStretch确定打印的时候是否伸缩,全局变量
begin
PrintHeight:=round(Printer.PageHeight/2.5);
PrintWidth:=PrintHeight*fScale;//fScale,伸缩系数,全局变量
Printer.Canvas.Font:=Font;
Printer.Canvas.Font.Size:=11;
Printer.Canvas.StretchDraw(Rect(0,0,Trunc(PrintWidth),Trunc(PrintHeight)),MyMetaFile);
end
else
begin
Printer.Canvas.Font:=Font;
Printer.Canvas.Font.Size:=11;
Printer.Canvas.Draw(40,40,MyMetaFile);
end;
Printer.EndDoc;
end;