为什么打印预览显示格式正确但实际上无法打印的页面?
我正在编写一个应用程序来使用 Visual Studio 2008/C# 打印格式化数据。我已按照我希望显示的方式格式化数据。我正在使用两个打印文档和事件处理程序,因为报告的第一页具有与第 2 页到第 N 页不同的格式要求。
打印预览向我显示我尝试打印的所有页面的格式正确的数据。然而,第 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();
}
谢谢大家抽出时间。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要打印文档,您可以使用:
预览时,将 PrintDocument 分配给 PrintPreviewDialog
当显示 PrintPreviewDialog 时,它将 PrintDocument 的 PrintController 替换为 PreviewPrintController 并调用 PrintDocument.Print。
此操作会生成一个图像(图元文件)列表,每页一个。
接下来,它在 PrintDocument 上恢复原始 PrintController 并显示图像。
当您按下 PrintPreviewDialog 上的 PrintButton 时,它会使用原始 PrintController 调用 PrintDocument.Print。
请注意,为了获得正确的行为,您可以使用 BeginPrint 的 PrintDocument 事件将变量初始化为新的 PrintDocument.Print。
如果您使用PrintPreviewDialog,则不需要调用PrintDocument.Print。
To Print a Document, you use:
When Preview, You assign The PrintDocument to PrintPreviewDialog
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.