I need to print two pages using PrintDocument, but there are some problems.
I've got something like that:
-button is pressed
-two pages need to be printed
The code is like that:
Expand|Select|Wrap|Line Numbers
- PrintDocument print_tab1 = new PrintDocument();
- in main():
- print_tab1.PrintPage += new PrintPageEventHandler(printTab1);
- private void print_tab1_but_Click(object sender, EventArgs e)
- {
- PrintDialog pd = new PrintDialog();
- pd.Document = print_tab1;
- if (pd.ShowDialog() == DialogResult.OK)
- {
- print_tab1.Print();
- }
- }
- private void printTab1(Object sender, PrintPageEventArgs e)
- {
- e.Graphics.DrawString("page 1", new Font("Times new roman", 14, FontStyle.Bold), Brushes.Black, 60, 10);
- e.HasMorePages = true;
- e.Graphics.DrawString("page 2", new Font("Times new roman", 14, FontStyle.Bold), Brushes.Black, 60, 10);
- e.HasMorePages = false;
- }
But I can't figure out how to insert page break BEFORE the page actually ends and print the data that is FOMED IN THE SAME METHOD.
I understand that after printing a single page the method exits. But it doesn't when the page still has space to print on it. So I've got "page 1" and "page 2" on the same page.
And if I return from printTab1 explicitly, than how should I call it again and print ONLY the second page?
Would appreciate any help.