1. Put the code that does the printing into a seperate method that returns a bool (True = there are more pages to print)
2. Change document_PrintPage to call it, setting e.HasMorePages to the result
private void document_PrintPage(object sender, PrintPageEventArgs e)
{
e.HasMorePages = DoPrint(e.Graphics);
}
private bool DoPrint(Graphics g)
{
List<string> propNames = new List<string>();
List<string> propValue = new List<string>();
Font titleFont = new Font("Arial", 22, System.Drawing.FontStyle.Regular);
string title = "Object State Default";
RectangleF rect = new RectangleF();
rect.X = 50.0F;
rect.Y = 30.0F;
rect.Width = 300.0F;
rect.Height = 50.0F;
SolidBrush brush = new SolidBrush(Color.Black);
Pen blackpen = new Pen(Color.Transparent);
Font printFont = new Font("Arial", 11, System.Drawing.FontStyle.Regular);
//Gets names of all properties
propNames = printObject(objtyp);
//Gets values of all properties
propValue = getPrintValues();
//Draws title of the page
g.DrawString(title, titleFont, brush, rect);
//Sets position for next rectangle
rect.Y = rect.Y + 75;
int i = lastIndex;
//i = lastIndex;
while (i < propValue.Count)
{
//e.Graphics.DrawRectangle(blackpen, x, y, width, height);
g.DrawString(propNames.ElementAt(i), printFont, brush, rect);
rect.X = rect.X + 300;
g.DrawString(propValue.ElementAt(i), printFont, brush, rect);
rect.X = 50.0F;
rect.Y = rect.Y + 30;
//&& i < propNames.Count && i < propValue.Count
if (rect.Y >= 1130)
{
lastIndex = i;
return true;
//rect.Y = 40.0F;
}
//else
//{
// return false;
//}
i++;
}
return false;
}