簡體   English   中英

為什么“打印預覽”顯示格式正確的頁面,而實際上卻無法打印?

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

我正在編寫一個使用Visual Studio 2008 / C#打印格式數據的應用程序。 我已經按照想要顯示的方式格式化了數據。 我正在使用兩個打印文檔和事件處理程序,因為報表的首頁所載格式要求與第二頁至第二頁不同。

“打印預覽”顯示了我嘗試打印的所有頁面的格式正確的數據。 但是,第2到N頁實際上不會打印。

我已逐步完成代碼,並且數據已正確傳遞到事件處理程序。 這是調用第二個打印文檔的事件處理程序的代碼塊。 我究竟做錯了什么?

         // 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();
        } 

謝謝大家的寶貴時間。

要打印文檔,請使用:

PrintDocument.Print

預覽時,將PrintDocument分配給PrintPreviewDialog

printPreview2.Document = ItemsPrintDocument;

當您顯示PrintPreviewDialog時,它將PrintDocument的PrintController替換為PreviewPrintController並調用PrintDocument.Print。

此操作將在每頁上生成一個圖像(元文件)列表。

接下來,它將在PrintDocument上還原原始的PrintController並顯示圖像。

當您按下PrintPreviewDialog上的PrintButton時,它將使用原始PrintController調用PrintDocument.Print。

請注意,對於正確的行為,您可以使用BeginPrint的PrintDocument事件將vars初始化為新的PrintDocument.Print。

如果使用PrintPreviewDialog,則不需要調用PrintDocument.Print。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM