在从PrintDialog类中选择打印选项后,我尝试将多个文档直接发送到打印机。
我需要检索所选的papersource。不幸的是,我只能找到打印机中的所有纸张来源,而不是选定的纸张来源。
下面是我的代码示例(简化版):
CrystalDecisions.CrystalReports.Engine.ReportDocument document;
//...
PrintDialog pDialog = new PrintDialog();
pDialog.ShowDialog();
document.PrintOptions.PrinterName = pDialog.PrinterSettings.PrinterName; //OK
//Here I need to set the papersource
//document.PrintOptions.PaperSource = ???
document.printToPrinter(pDialog.PrinterSettings.Copies, false, 0, 0)我是不是在用good对象来做这件事?
注意:由于我使用的是Windows7,PageSetupDialog没有提供打印机选项。
发布于 2012-11-20 22:31:01
我在Hans Passant的评论中找到了我问题的答案。多亏了他。
为了从PrintDialog中获取PaperSource,我必须给它设置一个假的PrintDocument。
PrintDialog不会直接保留纸张来源。相反,它设置PrintDialog.Document.DefaultPageSettings.PaperSource。
下面是它看起来的样子:
CrystalDecisions.CrystalReports.Engine.ReportDocument document;
PrintDialog pDialog = new PrintDialog();
pDialog.Document = new System.Drawing.Printing.PrintDocument();
pDialog.ShowDialog();
document.PrintOptions.PrinterName = pDialog.PrinterSettings.PrinterName;
document.PrintOptions.CustomPaperSource = pDialog.Document.DefaultPageSettings.PaperSource;
document.printToPrinter(pDialog.PrinterSettings.Copies, false, 0, 0);https://stackoverflow.com/questions/13462255
复制相似问题