By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

C# Printing Page Count

P: 10
Hi All,
Now i use the following code to print the data in C# 2005 application.
But i face the problem is total page number at the begining of first page. They want to get page number like : Page : 1 of 15.

Is there any suggesting how to get total page number.

Expand|Select|Wrap|Line Numbers
  1. Public int y = 0;
  2. Public int LineCount = 0;
  3. int yPosition =  50;
  4.                     e.Graphics.DrawString("Summary of Image Data", drawHeaderFont, drawBrush, 50, yPosition, drawFormat);
  5.  
  6.                     yPosition = yPosition + 30;
  7.                     e.Graphics.DrawString("Category", drawFont, drawBrush, 50, yPosition, drawFormat);
  8.                     e.Graphics.DrawString("No. of Image", drawFont, drawBrush, 260, yPosition, drawFormat);
  9.                     e.Graphics.DrawString("Percentage", drawFont, drawBrush, 360, yPosition, drawFormat);
  10.  
  11.                     int DListCount = Convert.ToInt32(lsvSummary.Items.Count.ToString());
  12.                     yPosition = yPosition + 30;
  13.  
  14.                     while (LineCount1 < DListCount)                
  15.                     {
  16.                         e.Graphics.DrawString(ListView1.Items[y].SubItems[1].Text.ToString(), drawFont2, drawBrush, 50, yPosition, drawFormat);
  17.                         e.Graphics.DrawString(ListView1.Items[y].SubItems[2].Text.ToString(), drawFont2, drawBrush, 280, yPosition, drawFormat);
  18.                         e.Graphics.DrawString(ListView1.Items[y].SubItems[3].Text.ToString(), drawFont2, drawBrush, 380, yPosition, drawFormat);
  19.  
  20.                         yPosition = yPosition + 30;
  21.                         LineCount1++;
  22.                         y++;
  23.  
  24.                         if (yPosition >= e.MarginBounds.Bottom)
  25.                         {
  26.                             e.HasMorePages = true;
  27.                             break;
  28.                         }
  29.                         else
  30.                         {
  31.                             e.HasMorePages = false;
  32.                         }
  33.                     }
  34. e.Graphics.DrawString("Print Date Time : " + DateTime.Now.ToString(), drawFont2, drawBrush, 50, e.PageBounds.Bottom - 50, drawFormat);
  35.             e.Graphics.DrawString("Page : " + PageCount + " of " + TotalPage, drawFont2, drawBrush, e.PageBounds.Right - 150, e.PageBounds.Bottom - 50, drawFormat);
  36.             PageCount = PageCount + 1;
Many Thanks
Jan 30 '09 #1

✓ answered by vekipeki

I think there is no other way but to process the whole document before printing to calculate the number of pages. Since you are using fixed increments (e.g. yPosition = yPosition + 30;), it should be easy to implement.

Share this Question
Share on Google+
2 Replies


vekipeki
Expert 100+
P: 229
I think there is no other way but to process the whole document before printing to calculate the number of pages. Since you are using fixed increments (e.g. yPosition = yPosition + 30;), it should be easy to implement.
Jan 30 '09 #2

P: 10
@vekipeki
Anyway, thank a lot vekipeki .....

I try this way .........
Feb 1 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.