URGENT : Panel printing on multiple pages C#
Hi guys
Hope some one will be able to help me. I have a class that needs to print a panel on more than one page. My printpreview shows the pages perfect but when i press print it throws me a blank page out of the printer?The last page on the print preview is also blank. But you can view the first pages that has data on but it doesn't print .
Can any one please help.
public class PrintClass
{
readonly PrintDocument printdoc1 = new PrintDocument();
readonly PrintPreviewDialog previewdlg = new PrintPreviewDialog();
Bitmap MemoryImage;
private readonly Panel panel_;
public PrintClass(Panel pnl)
{
panel_ = pnl;
printdoc1.PrintPage += (printdoc1_PrintPage);
MemoryImage = new Bitmap(pnl.Width, pnl.Height);
}
private int page = 0;
private void GetPrintArea(Control pnl)
{
page = 0;
MemoryImage = new Bitmap(pnl.Width, pnl.Height);
pnl.DrawToBitmap(MemoryImage, new Rectangle(0, 0, pnl.Width, pnl.Height));
}
private void printdoc1_PrintPage(object sender, PrintPageEventArgs e)
{
var pagearea = e.PageBounds;
e.Graphics.DrawImage(MemoryImage, new Rectangle(e.PageBounds.Location, e.PageBounds.Size), new Rectangle(e.PageBounds.Location.X, e.PageBounds.Height * page, e.PageBounds.Width, e.PageBounds.Height), GraphicsUnit.Pixel);
e.HasMorePages = e.PageBounds.Height * (page+1) < panel_.Size.Height;
page++;
}
public void Print()
{
GetPrintArea(panel_);
previewdlg.Document = printdoc1;
previewdlg.ShowDialog();
}
}