PrintPreviewDialog Print Button Does Not Work

Woodster

Newcomer
Joined
May 18, 2006
Messages
7
Hi everyone!

Have successfully set up a PrintPreviewDialog that shows the document to print very nicely. The dialog's Print button, however, just prints a blank sheet of paper. The document prints very nicely from other code in my app using PrintDocument's Print method but not from the PrintPreviewDialog.

Any advice would be appreciated.

Woodster

:cool:
 
If you call the "Print()" method on your PrintDocument component, it run's through the OnPrintPage event for each page of output that you intend to send to the printer.

If you first go into the PrintPreviewDialog, you run through this OnPrintPage event for each page of output you send to the screen, then, if you hit the embedded Print button, you run through OnPrintPage events AGAIN as you send each page of output to the printer.

In my scenario, I had a stack of complex Windows Forms controls that I stored in a generic List(Of Control). Within the OnPrintPage event handler, I was calling the .Dispose() method on each Windows Form that I sent to the printer, thinking "i'm done with this, better clean it out of memory". However, that left me with the blank page issue if users first previewed the output via the PrintPreviewDialog and *then* used it's embedded "Print" button.
 
my previous post assumes that the PrintPreviewDialog component you're using has it's Document property assigned correctly (referencing your PrintDocument component)
 
I highly recommend this article, to speed up performance of the PrintPreviewDialog and to circumvent the issue with my .Dispose() method that I was using (because the OnPrintPage was being called twice) you can inherit from Microsoft's PrintPreviewDialog and replace their print button with your own, and then use reflection to send to the printer the stuff you just created when you were rendering it to the screen. Much more efficient!!

http://www.codeproject.com/KB/dialog/SUPrintPreviewDialog.aspx
 
Back
Top