现在,我正在尝试打印一些我在表单中保存的位图。我有3个正在生成,但是当我将它们打印出来时,它只打印出来。
这是我的打印代码。
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));
}
除印刷品外,其他所有工作都正常。打印仅打印最后一页,但它正确地从列表中保存和加载。我最终在我的C:/ Test驱动器中有3个位图,label1分别读取1,2和3。但它只打印出第3页,其中label1读数为3。
对于hasmorepages的一些帮助,我尝试使用谷歌搜索,似乎这是MSDN上的确切代码,一群人使用,所以我迷路了。
答案 0 :(得分:1)
正如您可以在MSDN上阅读的那样,您的print_page处理程序应该一次向事件args中的图形对象提供一页...
因为你在彼此之上绘制了所有3张图像,所以最后一张图像存活,然后打印
因为在事件处理程序结束时HasMorePages为false,所以不再调用您的处理程序来打印下一页...
所以机器不能做你想做的......它只会按照你的指示......