首先将PaintBox里绘制的部分保存在一幅位图,然后就是位图的打印了。
BitBlt(bmp.canvas.handle,0,0,bmp.width,bmp.height,paintbox.canvas.handle,x,y,srccopy);
//x,y为你制定的起始坐标
//bmp.width,bmp.height为你确定的打印部分的宽度和高度
var
ScaleX,ScaleY :Integer;
R :TRect;
begin
if Printer.Printers.Count=0 then
begin
ShowMessage('请首先安装打印机');
Exit; //跳出N11Click
end;
if not MainPrintDialog.Execute then Exit
else
begin
with Printer do
begin
BeginDoc;
ScaleX :=GetDeviceCaps(Handle,LogPixelsX) div PixelsPerInch;
ScaleY :=GetDeviceCaps(Handle,LogPixelsY) div PixelsPerInch;
R :=Rect(0,0,bmp.Width*ScaleX,bmp.Height*ScaleY);
Canvas.StretchDraw(R,bmp);
EndDoc;
end;
end;
end;