我已经完成了使用打印机的应用程序。
这是打印代码:
this.printDocument1 = new System.Drawing.Printing.PrintDocument();
this.printDialog1 = new System.Windows.Forms.PrintDialog();
printDocument1.PrintPage += printDocument1_PrintPage;
this.printDocument1.Print();
现在我有一台名为XXX的打印机,其IP地址为192.168.2.200
请问如何打印到该打印机?
由于
this.printDocument1 = new System.Drawing.Printing.PrintDocument();
this.printDocument1.PrinterSettings.PrinterName = "MainPass";
this.printDialog1 = new System.Windows.Forms.PrintDialog();
printDocument1.PrintPage += printDocument1_PrintPage;
this.printDocument1.Print();
然后printDocument1_PrintPage
是:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString("PANTRY KOY", valueFont, Brushes.Black, width, height);
printDialog1.Document = printDocument1;
}
答案 0 :(得分:1)
如果你有一个PrintDialog
实例,这意味着你让用户选择一台打印机,你需要尊重那里选择的打印机。 (提示:您可以通过对话框PrinterName
属性的PrintSettings
属性设置对话框中显示的初始打印机。在那之后,我敢打赌,如果你浏览the documentation for the PrintDocument Properties,你会看到你需要做什么来设置打印机(提示:IP地址无关紧要,但PrinterName确实如此)。