![](/img/trans.png)
[英]Type or namespace name could not be found (missing using directive or assembly reference?)
[英]The type or namespace name 'PrintDocument' could not be found (are you missing a using directive or an assembly reference?)
我有一個舊的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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.