gpt4 book ai didi

c# - 为什么我的图像不能打印到 PrintDocument?

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:47 30 4
gpt4 key购买 nike

我在“C://”中有位图,名称为“1.bmp”、“2.bmp”、“3.bmp”等,我正在尝试打印这些图像,但打印文档是空的(图像在正确的路径中)

这是我的代码:

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 的影响。

关于c# - 为什么我的图像不能打印到 PrintDocument?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16302090/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com