Page 1 of 1

TPrintPreview : Cliprect

PostPosted: May 26th, 2007, 8:12 pm
by callostfound
First, many thanks to Kambiz for creating such a great Delphi component.

I have a problem in printing a large network map (a set of points and lines). I want to print only a portion of the map. So I used SelectClipRgn to change the ClipRect property of the printpreview canvas. PrintPreview seemed to display the resulting image correctly, but printed an empty page when I clicked on the print button. Not sure what caused the problem and how to solve the problem.

Any input is highly appreciated.

Below please find my code for this:

Code: Select all
///////////////////////////////////////////////////////////////////
procedure CreateMyPage;
var
  R, R0: TRect;
  MyRgn: HRGN
  with PrintPreview do
  begin
   R:=PageBounds;
   R0:=Canvas.ClipRect; {somehow, R0 is greatly different from R}
   OneCM := ConvertXY(100, 100, mmLoMetric, Units);
  end;
  InflateRect(R, -(OneCM.X), -(OneCM.Y)); {target region}
 
  MyRgn := CreateRectRgn(R.Left,R.top,R.Right,R.Bottom);

  SelectClipRgn(PrintPreview.Canvas.Handle, MyRgn); {change ClipRect}
  MapBoard.SetupPrintBoard (PrintPreview.Canvas); {pass canvas }
  MapBoard.Print; {MapBoard draw map objects here}
  SelectClipRgn(PrintPreview.Canvas.Handle, 0); {Restore default ClipR}
  DeleteObject(MyRgn);
End;
////////////////////////////////////////////////////////////

Jack

//Mod Edit: phpBB's code tag is hard to use, eh?

PostPosted: May 27th, 2007, 1:27 pm
by Kambiz
The DC represented by Canvas property depends on value of State property. When State is psCreating, the Canvas property represents the metafile canvas of the current page. Otherwise it's the printer canvas.

I hope this helps you to solve the problem.