Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

Below is the code i am using for printing specific number of lines per page

C#
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            float linesPerPage = 0;
            float yPos = 0;
            int count = 0;
            float leftMargin = e.MarginBounds.Left;
            float topMargin = e.MarginBounds.Top;
            string line = null;
            

            // Calculate the number of lines per page.
            linesPerPage = 30;

         
                //MessageBox.Show("Turn the page to continue");

                // Print each line of the file. 
                while (count < linesPerPage &&
                   ((line = streamToPrint.ReadLine()) != null))
                {

                    yPos = topMargin + (count *
                    printFont.GetHeight(e.Graphics));
                    e.Graphics.DrawString(line, printFont, Brushes.Black,
                       leftMargin, yPos, new StringFormat());
                    count++;

                }

              
                if (line != null)
                {
                    e.HasMorePages = true;
                   

                }
                else
                {
                    e.HasMorePages = false;
                }


But here suppose user has 40 lines to print, so at that time i want to display one messagebox after printing 30 lines.
once user tuen the page or put new page, it will print the remaining transactions.

Please help me how to do this..
Posted
Updated 8-Apr-14 18:59pm
v2
Comments
Maciej Los 9-Apr-14 1:55am    
Is this your real problem? Think about it! It's simple.

1 solution

Have a look at example:

C#
while (count < linesPerPage &&
   ((line = streamToPrint.ReadLine()) != null))
{
//here the condition is true and
//lines are printed to the limit
}

//check: limit was reached or there is no more lines
if (line != null)
{
    //limit was reached
}
else
{
    //no more lines ;)
}


Now, do you know where to display message?

As i mentioned it's quite simple ;)
 
Share this answer
 
Comments
[no name] 9-Apr-14 2:56am    
i am trying..i gave here
if (line != null)
{
//limit was reached
}
else
{
//no more lines ;)
}
but it's displaying the box 2 times.
i want like after printing 30 lines it should display the message

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