C# PrintDialog所选纸张来源
在从C# PrintDialog所选纸张来源,c#,.net,crystal-reports,printdialog,C#,.net,Crystal Reports,Printdialog,在从打印对话框类中选择打印选项后,我试图将多个文档直接发送到打印机。 我需要检索所选的papersource。不幸的是,我只能从打印机中找到所有纸张来源,而不是所选的纸张来源。 以下是我的代码示例(缩短版本): 我是否在使用“好对象”来执行此操作? 注意:PageSetupDialog没有为我提供打印机选项,因为我使用的是windows 7。我通过Hans Passant的评论找到了问题的答案。多亏了他。 为了从PrintDialog获取PaperSource,我必须为它设置一个假的Pr
打印对话框
类中选择打印选项后,我试图将多个文档直接发送到打印机。我需要检索所选的papersource。不幸的是,我只能从打印机中找到所有纸张来源,而不是所选的纸张来源。
以下是我的代码示例(缩短版本): 我是否在使用“好对象”来执行此操作?
注意:
PageSetupDialog
没有为我提供打印机选项,因为我使用的是windows 7。我通过Hans Passant的评论找到了问题的答案。多亏了他。为了从
PrintDialog
获取PaperSource
,我必须为它设置一个假的PrintDocument
。PrintDialog
不能直接保存papersource。相反,它设置了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);
PageSetupDialog不提供“打印机选项”,其文档属性提供“打印机选项”。首先选择打印机,然后是页面设置。问题是我可以在
PrintDialog
窗口中选择papersource,但我无法在代码中获取它以将其发送回我的文档。您需要分配PrintDialog.document属性。我的错,我忘了提到我正在尝试为Crystal report执行此操作(我的ReportDocument是CrystalDecisions.CrystalReports.Engine.ReportDocument
。编辑我的问题。找到了我的答案,谢谢你的评论,Hans,它指导了我!我会在它完全测试后发布它。介意解释一下否决票吗?可能有助于找到“真正”的解决方案。
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);