Charles Morissette

Charles Morissette

  • NA
  • 29
  • 42.8k

HasMorePages printing

Apr 22 2011 3:29 PM
right now, I am trying to print a few bitmaps I am saving in a form. I have 3 I am generating, but when I am printing them out, it only prints out 1.

This is my print code.

[CODE]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));
}[/CODE]

Everything else but the print is working properly. The print only prints the last page, but it saves and loads from the list properly. I end up with 3 bitmaps in my C:/Test drive with label1 reading 1, 2 and 3 respectively. But it only prints out page#3 with label1 reading 3.

Some help with hasmorepages, I tried googling and it seems this is the exact code on MSDN and a bunch of people use so I'm lost.


Answers (3)