在c#中打印位图-有多页问题

本文关键字:问题 位图 打印 | 更新日期: 2023-09-27 17:52:46

现在,我正试图打印一些位图,我保存在一个形式。我生成了3个,但是当我打印出来的时候,它只打印出1个。

这是我的打印代码。

private void PrintDoc_PrintPage(Object sender, PrintPageEventArgs e)
{
int bound1 = 0;
int bound2 = 0;
float boundsH = e.Graphics.VisibleClipBounds.Height;
float boundsW = e.Graphics.VisibleClipBounds.Width;
float boundsS = e.PageBounds.Height;
float boundsE = e.PageBounds.Width;
float CBound1 = boundsS - boundsH;
float CBound2 = boundsE - boundsW;
float boundHD = (boundsH - CBound1);
float boundHW = (boundsW - CBound2);
int bounds1 = Convert.ToInt32(boundHD);
int bounds2 = Convert.ToInt32(boundHW);
int check1 = ((bounds1 * 100) / OverPanel.Height);
int check2 = ((bounds2 * 100) / OverPanel.Width);
if (check1 < check2)
{
bound1 = (OverPanel.Height * check1) / 100;
bound2 = (OverPanel.Width * check1) / 100;
}
else
{
bound1 = (OverPanel.Height * check2) / 100;
bound2 = (OverPanel.Width * check2) / 100;
}
e.Graphics.DrawImage(AllPrints[0], 0, 0, bound2, bound1);
e.HasMorePages = true;
e.Graphics.DrawImage(AllPrints[1], 0, 0, bound2, bound1);
e.HasMorePages = true;
e.Graphics.DrawImage(AllPrints[2], 0, 0, bound2, bound1);
e.HasMorePages = false;
AllPrints[0].Save("C:/Test/1.bmp");
AllPrints[1].Save("C:/Test/2.bmp");
AllPrints[2].Save("C:/Test/3.bmp");[/CODE]
This code draws 1, 2 and 3 on the page for me to test my prints with.
[CODE]private void button1_Click(object sender, EventArgs e)
{
for (Locc = 1; Locc <= 3; Locc++)
{
label1.Text = Locc.ToString();
WholePage();
ClearPage();
}
}
}
PrintDocument PrintDoc = new PrintDocument();
PrintDoc.PrintPage += PrintDoc_PrintPage;
PrintDoc.Print();
}[/CODE]
This code saves the prints
[CODE]public void WholePage()
{
int x = 0;
int y = 0;
int width = OverPanel.Width;
int height = OverPanel.Height;
Rectangle Rec = new Rectangle(0,0,width,height);
PImage = new Bitmap(OverPanel.Width, OverPanel.Height);
OverPanel.DrawToBitmap(PImage, Rec);
AllPrints.Add(new Bitmap(PImage, PImage.Size));
}

除了打印,其他一切都工作正常。print只打印最后一页,但它可以正确地保存并从列表中加载。在我的C:/Test drive中,我最终得到了3个位图,其中label1分别读取1,2和3。但是它只打印出第3页,其中label1的读数为3。

一些帮助与hasmorepages,我试着谷歌,似乎这是确切的代码在MSDN和一群人使用,所以我迷路了。

在c#中打印位图-有多页问题

正如你可以在MSDN上读到的那样,你的print_page处理程序应该在事件参数中每次向图形对象传递一页…

由于您将所有3个图像绘制在彼此的顶部,因此最后一个保留下来并打印

由于在事件处理程序结束时HasMorePages为false,因此不会再次调用处理程序来打印下一页…

所以机器不会做你想要的…它只会听从你的指令……