如何在FastReport中显示预览后立即显示PrintDialog?

How to show the PrintDialog just after showing the preview in FastReport?

我正在使用 Delphi 开发桌面数据库应用程序,并且我有一份使用 FastReport[=15= 制作的发票报告], 我知道我可以使用 InvoiceReport.ShowReport 来显示它的预览。 所以我需要知道如何在显示预览后自动显示打印对话框。 然后用户可以打印它或取消对话框

InvoiceReport.ShowReport 之后立即调用 PrintDialog1.Execute

要在 Fast Report 中显示打印对话框,只需调用 PrintPrintOptions.ShowDialog:=True。默认情况下,预览表单以模式显示,因此最简单的解决方案是更改它并调用 Print:

InvoiceReport.PreviewOptions.Modal:=False;
InvoiceReport.PrintOptions.ShowDialog:=True;
InvoiceReport.ShowReport;
InvoiceReport.Print;

如果您需要保持预览表单模态,另一种选择是处理 OnPreview 事件并调用 Print,但您必须推迟该过程,例如:

const 
  UM_PRINT_DIALOG = WM_USER+1;

...

procedure ShowPrintDialog(var Message: TMessage); message UM_PRINT_DIALOG;

...

procedure TForm1.Button1Click(Sender: TObject);
begin
  InvoiceReport.ShowReport;
  //if you want to show the report once it is fully rendered use:
  //InvoiceReport.PrepareReport;
  //InvoiceReport.ShowPreparedReport;
end;

procedure TForm1.InvoiceReportPreview(Sender: TObject);
begin
  PostMessage(Handle,UM_PRINT_DIALOG,0,0);
end;

procedure TForm1.ShowPrintDialog(var Message: TMessage);
begin
  InvoiceReport.PrintOptions.ShowDialog:=True;
  InvoiceReport.Print;
end;