Home Devices
New Blog Posts: Merging Reports - Part 1 and Part 2

Print Preview form question: How do I automatically close it in code

edited September 2005 in Devices
Scenario:

ModalPreview of report is true
Report.devicetype = 'Screen'
Report.print; // prints the report and it is displayed in the print preview
dialog form.


User presses a print preview button.
The report is displayed inside of the print preview form.
User clicks on either File|Print or the speed button Printer

The following code is executed:
{ TppPrintPreview.spbPreviewPrintClick }

procedure TicsPrintPreviewDlg.spbPreviewPrintClick(Sender: TObject);
begin
ppViewer1.Report.DeviceType := 'Printer';
ppViewer1.Report.ShowPrintDialog := True;
ppViewer1.Print;
end; {procedure, spbPreviewPrintClick}


The print dialog form will display .

How do I and at what point:
1) In code set the device type := 'Report Emulation Text'

2) In code close the print preview form automatically after user clicks the
OK button of the print dialog form.

Your assistance is greatly appreciated.

Karen

Comments

  • edited September 2005
    Hi Karen,

    Try using a combination of the PrintDialog events and the AfterPrint event.
    The following code worked for me (although there are probably many ways to
    do this).

    private
    FPreviewClose: Boolean;
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    FPreviewClose := False;
    ppReport1.Print;
    end;

    procedure TForm1.ppReport1AfterPrint(Sender: TObject);
    begin
    if FPreviewClose then
    ppReport1.PreviewForm.Close;
    end;

    procedure TForm1.ppReport1PrintDialogCreate(Sender: TObject);
    begin
    FPreviewClose := True;
    end;

    end.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.