In FastReport 2019.4 added the ability to subscribe to PreviewControl.OnPrint and PreviewControl.OnExport events, which are called directly when the corresponding buttons are pressed.
When viewing a report, a viewer is called with a toolbar that has elements such as a print button and a drop-down list with report exports. Selecting any item in the list will trigger the OnExport event, and pressing the Print button will trigger OnPrint. Let's take an example and see how we can use these events in practice.
You can use the standard handler for these events, which is created for the visual component of PreviewControl:
In this case you just add the necessary actions to the handler.
But if you add the PreviewControl component in the application code, you will have to sign your own handler for the event. For example, your handler may send you an export or print event alert. This could be, for example, a record in a database. Let us consider this example:
After creating the report object and registering data in it, we create a PreviewControl, subscribe to the OnExport event our event handler, which we will implement below. Then we assign the PreviewControl object to the preview report. And now we implement a custom event handler for the OnExport event:
In this method, we record information about the export event in a database, with the report name, export type and transaction date. This is just one possible example of how to use this event. You can, for example, implement sending an email on this event, or saving an export file to a specific folder.
The OnPrint event is handled in the same way.
These two events are the most frequent operations on reports when viewed, so many people would like to automate their custom operations on the event. Now it is possible, it is easy to take information about the report, export or print settings from event arguments and dispose of it to create your own, additional operations.