Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how do i print the second image in the second page of the print document..
C#
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        Graphics graphics = e.Graphics;

        Image bgFront = ((PictureBox)pictureBox_IDFront).Image;
        e.Graphics.DrawImage(bgFront, 0, 0, 212, 337);


        Image bgBack = ((PictureBox)pictureBox_IDBack).Image;
        e.Graphics.DrawImage(bgBack, 212, 0, 212, 337);
    }

i want to print the second image to another page. i will only need 2 pages for this. the front and the back image. each pages includes some string like this is for the second page. the back page.
C#
e.Graphics.DrawString("Employee Information", printFont, Brushes.Black, y, x);
        x = x + (printFont.Size + spacing);
        e.Graphics.DrawString("Name: " + this.label_FullName.Text, printFont, Brushes.Black, y, x);
        x = x + (printFont.Size + spacing);
        e.Graphics.DrawString("Address: ", printFont, Brushes.Black, y, x);

thank you very much for your help.

What I have tried:

i tried e.hasmorepages but i don't know where to put my codes. thank you.
Posted
Updated 9-Aug-16 22:26pm
Comments
Richard MacCutchan 10-Aug-16 4:04am    
You need to add the code to your printing method to check which page you are on when it gets called.
Member 12620816 10-Aug-16 4:11am    
that's my problem. i don't know how to determine which page i am on. can you pls show it to me. i'm sorry. i've been trying this for weeks now. every time i use hasmorepages i get more like unlimited pages. sorry for my English. thank you.
Richard MacCutchan 10-Aug-16 4:17am    
Create a counter that lets you know which page you are on.
Member 12620816 10-Aug-16 4:39am    
int pages = 1;
if (pages == 1)
{
Image bgFront = ((PictureBox)pictureBox_IDFront).Image;
e.Graphics.DrawImage(bgFront, 0, 0, 212, 337);
pages++;
e.HasMorePages = true;
}
else
{
Image bgBack = ((PictureBox)pictureBox_IDBack).Image;
e.Graphics.DrawImage(bgBack, 212, 0, 212, 337);
pages = 0;
e.HasMorePages = false;
}


i know this is wrong coz it will only call one of them. i don't know where to put the second page. i've tried both if and it still print both images on the same page. thank you.
Richard MacCutchan 10-Aug-16 4:51am    
See Duncan's explanation below. Your page count must be at class level, not local to this method.

Have a quick read of: An absolute beginner's guide to printing in .NET[^]

The PrintPage routing gets called once for every page printed and will continue on if e.HasMorePages is True

You need a page count variable declared outside of that routine that you update and - if pagecount = 2 then e.HasMorePages = False

You can also use that same variable to decide what image to print.
 
Share this answer
 
Comments
Member 12620816 10-Aug-16 9:32am    
thank you. :)
When you do multipage printing, it's up to you to decide which page you are printing at any moment, as showed in MSDN: How to: Print a Multi-Page Text File in Windows Forms[^]
That example prints from a string, and removes the printed part from it for next time, but it's exactly the same principle with images: either keep a class level variable which tells you which page you are on, or set up a collection of images to print and remove each from the collection when you print it.
 
Share this answer
 
Comments
Member 12620816 10-Aug-16 9:32am    
thank you. :)
OriginalGriff 10-Aug-16 9:36am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900