I'm having trouble creating multiple pages in a PrintDocument and displaying them within a PrintPreviewControl. I can create a single page easily enough, but stringing together multiple pages is eluding me.
I'm going to eventually draw several pages of stuff using GDI, but I can't get something like this to work as expected.
private PrintDocument doc = new PrintDocument();
private string[] printMe = new string[]{ "page1", "page2", "page3" );
private int pageCount = 0;
private void FormLoad(object sender, EventArgs e)
{
doc.PrintPage += new PrintPageEventHandler(PrintPage);
PrintPreviewControl.Document = doc;
}
private void doc_BeginPrint(object sender, PrintEventArgs e){ pageCount = 0; }
private void PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
g.DrawString(drawMe[pageCount++], "Lucida Console", Brushes.Black, new Point(20,20));
e.HasMorePages = (pageCount printMe.Length );
}
The idea being that 3 separate pages are created, and displayed within the PrintPreview control. What am I missing?