To show print dialog in Fast Report you simply call Print
with PrintOptions.ShowDialog:=True
. By default the preview form is shown modal, so the easiest solution is to change it and call Print
:
InvoiceReport.PreviewOptions.Modal:=False;
InvoiceReport.PrintOptions.ShowDialog:=True;
InvoiceReport.ShowReport;
InvoiceReport.Print;
If you need to keep the preview form modal, the other option is to handle OnPreview
event and call Print
, but you have to postpone the procedure, so for example:
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;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…