【发布时间】:2021-01-11 09:07:14
【问题描述】:
我正在使用 Delphi 开发桌面数据库应用程序,并且我有一个使用 FastReport 制作的发票报告,我知道我可以使用 InvoiceReport.ShowReport 来显示它的预览。
所以我需要知道如何在显示预览后自动显示打印对话框。
然后用户可以打印或取消对话框
【问题讨论】:
标签: delphi fastreport
我正在使用 Delphi 开发桌面数据库应用程序,并且我有一个使用 FastReport 制作的发票报告,我知道我可以使用 InvoiceReport.ShowReport 来显示它的预览。
所以我需要知道如何在显示预览后自动显示打印对话框。
然后用户可以打印或取消对话框
【问题讨论】:
标签: delphi fastreport
要在快速报告中显示打印对话框,您只需调用Print 和PrintOptions.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;
【讨论】:
在InvoiceReport.ShowReport 之后立即致电PrintDialog1.Execute。
【讨论】: