我有一个旧的Windows Form App,其代码如下:
public static void PrintTheNumber(int numberOfLabels, string toPrint)
{
PrintDocument p = new PrintDocument();
p.PrintPage += delegate (object sender1, PrintPageEventArgs e1)
{
e1.Graphics.DrawString(toPrint, new Font("Times New Roman", 12),
new SolidBrush(Color.Black),
new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));
};
try
{
p.PrinterSettings.Copies = (short)numberOfLabels;
p.Print();
}
catch (Exception ex)
{
throw new Exception("Printer error!");
}
}
现在,我将其转换为WPF,并且从问题中得到了这个错误。
我被卡住了,不知道现在如何使用WPF打印。如果有人可以向我解释这是什么问题?
我只想单击按钮即可打印字符串。
请参阅文档。
该类在System.Drawing.dll中定义;您需要添加对该程序集的引用(并包括名称空间)。
然后,您可以像这样在类的顶部将其导入:
using System.Drawing;
using System.Drawing.Printing;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句