[Printpreview] Pageborder

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

[Printpreview] Pageborder

Postby Jens01 » April 18th, 2011, 5:51 pm

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
Jens01
Active Member
Active Member
 
Posts: 19
Joined: December 10th, 2010, 12:10 pm

Re: [Printpreview] Pageborder

Postby Kambiz » April 18th, 2011, 8:13 pm

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.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: [Printpreview] Pageborder

Postby Jens01 » April 19th, 2011, 1:02 pm

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!
Jens01
Active Member
Active Member
 
Posts: 19
Joined: December 10th, 2010, 12:10 pm

Re: [Printpreview] Pageborder

Postby Kambiz » April 19th, 2011, 2:45 pm

You can also set ShowPrintableArea and Background properties at the same time.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Re: [Printpreview] Pageborder

Postby Jens01 » April 19th, 2011, 2:56 pm

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;
Jens01
Active Member
Active Member
 
Posts: 19
Joined: December 10th, 2010, 12:10 pm

Re: [Printpreview] Pageborder

Postby Kambiz » April 20th, 2011, 4:57 am

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.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 4 guests

cron