为什么我的图像不能打印到PrintDocument?
我有“C://”中名称为“1.bmp”,“2.bmp”,“3.bmp”等位图,我试图打印这些图像,但打印文档是空的图像是在正确的路径)为什么我的图像不能打印到PrintDocument?
这里是我的代码:
private void button3_Click_1(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
for (int indice = 0; indice < nPaginasPDF + 1; indice++)
{
pd.PrintPage += new PrintPageEventHandler(Print_Page);
}
PrintPreviewDialog dlg = new PrintPreviewDialog();
dlg.Document = pd;
dlg.ShowDialog();
pd.Print();
}
private void Print_Page(object o, PrintPageEventArgs e)
{
nPaginasImpressas++;
System.Drawing.Image i = System.Drawing.Image.FromFile("C:\\" + nPaginasImpressas + ".bmp");
Point p = new Point(891, 1350);
e.Graphics.DrawImage(i, p);
}
确定,因此通过页面的打印利用了PrintPageEventArgs
类,并多次不重视该事件的过程。考虑以下代码:
private void button3_Click_1(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(Print_Page);
PrintPreviewDialog dlg = new PrintPreviewDialog();
dlg.Document = pd;
dlg.ShowDialog();
pd.Print();
}
private void Print_Page(object o, PrintPageEventArgs e)
{
nPaginasImpressas++;
System.Drawing.Image i = System.Drawing.Image.FromFile("C:\\" + nPaginasImpressas + ".bmp");
Point p = new Point(0, 0);
e.Graphics.DrawImage(i, p);
e.HasMorePages = File.Exists("C:\\" + (nPaginasImpressas + 1) + ".bmp");
}
此代码应允许您打印多个页面。但请注意对Point
的更改 - 这对我来说是相当可疑的,然后是HasMorePages
的杠杆作用。
和程序如何知道有多少页? – 2013-04-30 14:26:51
@AranhaSilva,只要它在下一个序号中找到位图,就会继续打印,请注意这行'e.HasMorePages = File.Exists(“C:\\”+(nPaginasImpressas + 1)+“)。 BMP“);'。 – 2013-04-30 14:27:49
它的效果很好......而且我的代码也是......问题是Point p = new Point(891,1350); – 2013-04-30 14:34:49
nPaginasImpressas.ToString()何时连接正确? – Edper 2013-04-30 14:20:02
也不起作用 – 2013-04-30 14:21:21
我试图改变路径var path =“C:\”+ nPaginasImpressas.ToString()+“.bmp”; 但我得到编译错误 – 2013-04-30 14:28:02