【发布时间】:2013-06-04 20:27:28
【问题描述】:
这是我使用的代码(只是与打印相关的部分):
按钮 1 onclick 处理方法:
printDialog1 = new PrintDialog();
printDialog1.AllowPrintToFile = true;
printDialog1.PrintToFile = false;
if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
PrintDocument pd = new PrintDocument();
pd.DefaultPageSettings.PaperSize = new PaperSize("A4", 826, 1169);
pd.PrinterSettings.PrintToFile = true;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
}
还有我的 pd_PrintPage 方法:
Bitmap bitmapCanvas = new Bitmap(1000, 1000);
Graphics g = Graphics.FromImage(bitmapCanvas);
g.Clear(Color.White);
...
some g.Draw...() stuff
...
e.Graphics.DrawImage(bitmapCanvas, A(2), A(2));
//where e is the PrintPageEventArgs defined in the method signature
我的问题的第一部分是,这不会打印到选定的打印机(在打印对话框中选择)。 如果这是默认打印机,它只会打印到打印机。 在 Windows 7 下它可以工作,它可以识别默认打印机,因此默认情况下,默认打印机将在我单击按钮后出现的打印对话框的组合框中选择。
我的主要问题是,这在 Windows Xp 下根本不起作用(不幸的是我只能使用它)。我有点好奇为什么。所以不知道是我弄的乱七八糟,还是Windows Xp下不支持。
我应该用什么来完成或更正我的代码?
感谢您的任何帮助,非常感谢您! 米图拉特巴蒂
【问题讨论】:
-
您期待什么?使用 PrinterSettings 属性。
-
你认为我在期待什么?我应该设置哪些属性来达到我的目标?
-
我告诉你要使用的,
PrintDocument.PrinterSettings。 -
您创建了 PrintDialog 但从不使用它,当您编辑纸张大小时,您希望对 printDialog1.Document 属性进行操作,您只需创建一个可能使用默认打印机的新属性.
-
newStackExchangeInstance:PrinterSettings 是一个具有属性的类。我的问题是关于这些属性的……但我想现在我明白了。谢谢!
标签: c# printing printdocument printdialog