[2005] - ReportViewer: how to find out if the user has printed
Got a bit of a problem with the reportviewer in VB.Net.
I'm trying to determine if a user has printed a report from the ReportViewer control, so I can write the date/time and username to a database table as part of an audit trail.
When the user opens a report there is a print button, which calls up a standard print dialog box. However I can't find any way to determine whether the print button has been clicked or not. The reportviewer has a Print event, but this is no good as it's called before the print dialogue is displayed.
What I ideally need to do is to check the status of the print dialog form to see if the user clicked Print or Cancel. But there seems to be no clear way to do this...
Re: [2005] - ReportViewer: how to find out if the user has printed
As the print dialog is a windows standard form, you might need to add the pintdocument or printdialog control (see screenshot attached) to access the events in there.
Re: [2005] - ReportViewer: how to find out if the user has printed
Ta - I was also looking into that method as well. In order for it to work, you need to assign the Document property of the PrintDialog control (which is your document to be printed).
This seems straightforward if you're say, printing a PDF document saved somewhere. But I can't see how to pass the generated report in the reportviewer to the PrintDialog document property...
I could export the report as a PDF first then print it, but I would rather pass the report straight to the PrintDialog control as I may not have access to save the report somewhere.
Re: [2005] - ReportViewer: how to find out if the user has printed
I don't know how you can catch the click event of the OK button on the print dialog, but you can certainly catch the click event of the print button on the crystalreportviewer control. This button when clicked, all it does is to call crystalreportviewer.PrintReport() method. This PrintReport method will show a print dialog to the user and goes on to print the report if the dialogresult returned from the print dialog = dialogresult.OK.
So, since we know how it works, we can tap into the ToolStrip of the crystalreportviewer and replace the original print button with one our own. We the handle our own print button.click event. That way, we know exactly when the user clicks the print button. However, do not know if the user actual print the report or not, since we can't get a reference of the print dialog. All we can tell is the user clicked the print button.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -