【发布时间】:2020-03-24 15:06:47
【问题描述】:
我有以下在 winforms 和 C# 中运行良好的代码:
printDialog = new PrintDialog();
if (DialogResult.OK == printDialog.ShowDialog())
{
try
{
PrintDocument pd = new PrintDocument();
PrinterSettings ps = new PrinterSettings();
pd.PrintPage += new PrintPageEventHandler(PrintImage);
pd.PrinterSettings = printDialog.PrinterSettings;
pd.Print();
}
catch
{
}
}
现在在 wpf 中表明该行有错误:
pd.PrinterSettings = printDialog.PrinterSettings;
所以为了测试其余代码是否有效,我对其进行了注释并且效果很好,但显然它总是在 PC 默认配置的打印机上打印。
我试图在其他线程中研究如何解决这个问题,解决方案应该如下:
printDialog.PrintQueue = new PrintQueue(new PrintServer(), "The exact name of my printer");
但执行此操作会产生错误:
严重性代码描述项目文件行状态已删除 错误 CS0012 类型“PrintQueue”在未引用的程序集中定义。您必须添加对程序集的引用 'System.Printing, Version = 4.0.0.0, Culture = Neutral,
欢迎任何cmets或建议。
【问题讨论】:
-
您需要添加对
System.Printing.dll、source的引用 -
还有一个问题有没有办法从 printDialog 中获取所选打印机的名称?
-
:) -> pd.PrinterSettings.PrinterName = printDialog.PrintQueue.Name;
标签: c# wpf printdialog