Page 1 of 1
[Printpreview] Pageborder

Posted:
April 18th, 2011, 5:51 pm
by Jens01
Dear Kambiz,
among the printerborder I want draw the pageborder on the preview. But after now 3 hours I know it not so easy as I hoped.
I want to draw them as the printerborder with light-gray dotline. Are there a OnPaint-Event I can use?
Thanking you in anticipation
Jens
Re: [Printpreview] Pageborder

Posted:
April 18th, 2011, 8:13 pm
by Kambiz
Set Background property to true, then write a handler for OnBackground event to draw the border in preview.
If you want to draw the border in print, you should use OnPrintBackground event.
I hope this helps.
Re: [Printpreview] Pageborder

Posted:
April 19th, 2011, 1:02 pm
by Jens01
I tried it with OnBackground. Yes it draws the border but I want to switch it on and off the same time with ShowPrintableArea. But OnBackground doesnt fire when the Paperwiew is refreshed. It allways draws the paperborders.
[EDIT]
The solution is UpdateBackground!
Re: [Printpreview] Pageborder

Posted:
April 19th, 2011, 2:45 pm
by Kambiz
You can also set ShowPrintableArea and Background properties at the same time.
Re: [Printpreview] Pageborder

Posted:
April 19th, 2011, 2:56 pm
by Jens01
Yes, I did but if I click the button to switch ShowPrintableArea it doesnt fire the OnBackground-Event. Only with UpdateBackground it works.
- Code: Select all
procedure TPreviewFenster.btnAreaClick(Sender: TObject);
begin
PrintPreview1.ShowPrintableArea := not PrintPreview1.ShowPrintableArea;
PrintPreview1.UpdateBackground;
end;
procedure TPreviewFenster.PrintPreview1Background(Sender: TObject; PageNo: Integer;
Canvas: TCanvas);
begin
if PrintPreview1.ShowPrintableArea then
with Canvas do
begin
with PageBoundsAfterMargin do
begin
// We are going to draw a rectangle on the page to distinguish the page's
// margin. The margin is already calculated in the GeneratePages function.
Pen.Mode := pmMask;
Pen.Width := 0;
Pen.Style := psDot;
Pen.Color := PrintPreview1.PrintableAreaColor;
Rectangle(Left, Top, Right, Bottom);
end;
end;
end;
function TPreviewFenster.PageBoundsAfterMargin: TRect;
begin
Result := PrintPreview1.GetPageSetupParameters(PageSetupDialog);
end;
Re: [Printpreview] Pageborder

Posted:
April 20th, 2011, 4:57 am
by Kambiz
Usually all pages share a single background (for example, your case). Therefore, the background is drawn only once to save a bit memory and CPU time. And, if it needs to be updated, UpdateBackground is called.