我有以下代码,它们在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,区域性=中性,
欢迎任何意见或建议。
发布于 2020-03-24 21:23:48
wpf的解决方案是向System.Printing.dll添加添加引用(谢@Sinatr ),代码如下所示:
PrintDocument pd = new PrintDocument();
PrinterSettings ps = new PrinterSettings();
pd.PrintPage += new PrintPageEventHandler(PrintImage);
pd.PrinterSettings.PrinterName = printDialog.PrintQueue.Name;
pd.Print();
https://stackoverflow.com/questions/60833733
复制相似问题