Reputation: 15047
I had an old Windows Form App with this code:
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!");
}
}
And now I am converting it to WPF and I get exactly this error from my question.
I am stuck and don't know how to print now with WPF. If anyone could explain it to me what is the problem?
I just want to print a string on a click of a button.
Upvotes: 1
Views: 2694
Reputation: 887453
See the documentation.
That class is defined in System.Drawing.dll; you need to add a reference to that assembly (and include the namespace).
And then you can just import it at the top of your class like this:
using System.Drawing;
using System.Drawing.Printing;
Upvotes: 4