This blog will describe some of the learning experiences that I have with .NET, some personal projects that I'm working on, and whatever other topics tickle my fancy.
My Blog Links
Wednesday, March 10, 2004
I just answered a post on GotDotNet about PrintDocument.Print only printing a blank page after showing the print preview dialog. This has happened to me a few times and seems to be something that others get tripped up on as well, so I decided to put up an entry about it.
Your PrintDocument works fine when the user just prints it first. However, if the user does a print preview followed by a print, the result is a blank page rather than what it should be.
The PrintDialog uses the same instance of the PrintDocument as the PrintPreviewDialog, so you need to be sure to reset any important data during PrintDocument.OnBeginPrint. So, if you have anything that may be traversing lists or tables or keeping track of page numbers or whatever, they get set during the first run in the PrintPreviewDialog. So, when the PrintDialog is actually run, your PrintDocument may think it's already printed everything it needed to.
If this is the problem, you should be able to simulate it by calling the PrintPreviewDialog twice in a row with the same PrintDocument.
Here is a very good article on MSDN about .NET WinForms printing.
Comments: Post a Comment