我的代码导致saveFileDialog保存.xps文件而不是实际打印任何内容。我的代码有问题吗?如果没有,我如何配置我的机器以使此代码有效?
class Printer {
public Printer() {
}
private void PrintDocument_PrintPage(Object sender, PrintPageEventArgs e) {
Font printFont = new Font("Courier New", 12);
e.Graphics.DrawString(StringToPrint, printFont, Brushes.Black, 0, 0);
}
private PrintDocument pd = new PrintDocument();
private string StringToPrint;
public void PrintString(string input) {
pd.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
StringToPrint = input;
pd.Print();
}
}
代码:
Printer Printer = new Printer();
Printer.PrintString("Hello world");
答案 0 :(得分:4)
必须将“Microsoft XPS Document Writer”打印机设置为默认打印机。