简体   繁体   中英

Why does Print Preview show properly formatted pages that won't actually print?

I am writing an app to print formatted data using Visual Studio 2008/C#. I have formatted the data in the fashion that I want it to display. I am using two Print Documents and event handlers, because the first page of the report carries formatting requirements that differs from pages 2 through N.

Print Preview shows me properly formatted data for all pages that I try to print. Nevertheless, pages 2 through N will not actually print.

I've stepped through my code and the data is being passed correctly to the event handler. This is the block of code that calls the second print document's event handler. What am I doing wrong?

         // First page print limit has been reached. Do we
        //  still have unprinted items in the arraylist? Call the second 
        //  print handler event and print those items.
        if (((alItemsToPrint.Count) - iItemPrintedCount) > 0)
        {
            // Getting a look at my formating
            PrintPreviewDialog printPreview2 = new PrintPreviewDialog();
            printPreview2.Document = ItemsPrintDocument;
            printPreview2.ShowDialog();
            printPreview2.Dispose();                               

            // Print item overflow pages
            ItemsPrintDocument.Print();

            // Release the resources consumed by this print document
            ItemsPrintDocument.Dispose();
        } 

Thanks for your time, everyone.

To Print a Document, you use:

PrintDocument.Print

When Preview, You assign The PrintDocument to PrintPreviewDialog

printPreview2.Document = ItemsPrintDocument;

When You show PrintPreviewDialog, it replaces the PrintDocument' PrintController to PreviewPrintController and call PrintDocument.Print.

This action generates a List of images (metafiles) one on each page.

Next, it restore the original PrintController on PrintDocument and show images.

When You press the PrintButton on PrintPreviewDialog, it calls PrintDocument.Print with original PrintController.

Note that for correct behavior you can use BeginPrint' PrintDocument event to initialize vars to new PrintDocument.Print.

If you use PrintPreviewDialog, you do´nt need call PrintDocument.Print.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM