Hi,
I want to monitor the progress of creating a print job and then decide whether to print or not. The drawing is quite lengthy and complex and takes a little while to complete, so rather than draw it twice (once to the screen and once to the printer canvas) I thought I could do this by drawing to the printer canvas, then stretch-blitting the printer canvas to an on-screen canvas.
This works OK if the source is a bitmap canvas (see the trivial drawing exercise in Button1Click below) but doesn't if the source is the printer.canvas (Button2Click). Obviously the printer canvas is handled differently (even though it is a TCanvas object).
Have I missed something or is this a bad approach? Am I stuck with drawing twice?
Thanks,
Rob
8< ---------------------------------------------------------------------------------------
// Put two TButtons,a TImage and a TCheckBox (Name := "I_Want_To_Print") on a form
// Add Printers to the uses clause
procedure TForm1.Button1Click(Sender: TObject); var sR, dR: TRect; B: TBitMap; begin B := TBitMap.Create; try B.Width := 210; B.Height := 297;
sR := Rect(0,0,B.Width,B.Height); dR := Rect(0,0,Image1.Width,Image1.Height);
B.Canvas.Pen.Width := 5; B.Canvas.MoveTo(10,10); B.Canvas.LineTo(200,200); B.Canvas.TextOut(100,100,'Hello world!');
StretchBlt(Image1.Canvas.Handle, dR.Left, dR.Top, dR.Right, dR.Bottom,
B.Canvas.Handle, sR.Left, sR.Top, sR.Right, sR.Bottom,
SrcCopy);
Image1.Refresh;
finally
B.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject); var sR, dR: TRect; begin
sR := Rect(0,0,Printer.PageWidth,Printer.PageHeight); dR := Rect(0,0,Image1.Width,Image1.Height);
Printer.BeginDoc; Printer.Canvas.Pen.Width := 20; Printer.Canvas.MoveTo(10,10); Printer.Canvas.LineTo(200,200); Printer.Canvas.TextOut(200,200,'Hello world!');
StretchBlt(Image1.Canvas.Handle, dR.Left, dR.Top, dR.Right, dR.Bottom,
Printer.Canvas.Handle, sR.Left, sR.Top, sR.Right, sR.Bottom,
SrcCopy);Image1.Refresh;
if I_Want_To_Print.Checked then
Printer.EndDoc
else
Printer.Abort;
end;
_______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

