Joe

Joe

  • NA
  • 1
  • 0

Print out a List of Graphics in C# Windows Form App

Sep 30 2008 9:24 AM
I wrote some C# functions that output a List of System.Drawing.Graphics (List<System.Drawing.Graphics>) objects. they then return the List to a PrintDocument object which I want to have print out each item in the list as a page in a multipage print job. For some reason the first page prints out fine but each successive page comes out blank. Here is my print page event code.

Graphics ReportLayout;
List<Graphics> g = new List<Graphics>();

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
ReportLayout = e.Graphics;

float leftMargin = e.MarginBounds.Left / 100;
float rightMargin = e.MarginBounds.Right / 100;
float topMargin = e.MarginBounds.Top / 100;
float bottomMargin = e.MarginBounds.Bottom / 100;
float width = e.MarginBounds.Width / 100;
float height = e.MarginBounds.Height / 100;

//Make Pages only once
if (pagesmade == false)
{
//returns a List<Graphics>
g = RT.WriteReport(e);
pagesmade = true;
}

//if pages remain there are more pages to print
if (iterate < g.Count-1)
{
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
}

ReportLayout = g[iterate];

iterate++;
}

I'm kind of at a loss any suggestions would be greatly appreciated.