user3997094
user3997094

Reputation:

printing multiple pages in C#

I would to print 2 pages in my application but when I use this code behind, I'm in a never ending loop.

e.HasMorePages = true;

e.Graphics.DrawString("hello", new Font("Verdana", 12), new SolidBrush(Color.Black), new Point(10, 10));
e.Graphics.DrawString("page 2", new Font("Verdana", 12), new SolidBrush(Color.Black), new Point(10, 2000));

If I place e.HasMorePages = true; in comment he print only the first page. Can anyone help me?

Upvotes: 2

Views: 518

Answers (1)

Hassan Ahmed
Hassan Ahmed

Reputation: 405

e.HasMorePages has no effect in the middle of a print routine. So in your case, create a global variable e.g. count = 1, and then:

if (count == 1) {
   e.Graphics.DrawString("hello" + count, new Font("Verdana", 12), new SolidBrush(Color.Black), new Point(10, 10));
   e.HasMorePages = true;
}
else {
    e.Graphics.DrawString("Hello Again", New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 100, 100)
    e.HasMorePages = false;
}

count++;

PS: I haven't tried this code myself though.

Upvotes: 1

Related Questions