【问题标题】:How to show the PrintDialog just after showing the preview in FastReport?如何在 FastReport 中显示预览后显示 PrintDialog?
【发布时间】:2021-01-11 09:07:14
【问题描述】:

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

【问题讨论】:

    标签: delphi fastreport


    【解决方案1】:

    要在快速报告中显示打印对话框,您只需调用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;
    

    【讨论】:

    • 第一个解决方案对我来说已经足够了!
    【解决方案2】:

    InvoiceReport.ShowReport 之后立即致电PrintDialog1.Execute

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-31
      • 1970-01-01
      • 2015-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多