473,421 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

C# Printing Page Count

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.

2 11213
vekipeki
229 Expert 100+
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
winzone
10
@vekipeki
Anyway, thank a lot vekipeki .....

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

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

Similar topics

4
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been...
5
by: Patrick De Ridder | last post by:
How can I turn what I want to print 90 degrees using the logic below? Please tell me the code with which to make the modification. Many thanks, Patrick. using System.ComponentModel; using...
3
by: Tim | last post by:
Hi, I am creating my own method for printing. I am using PrintDocument and cycling through the data and creating new pages as neccessary. My question is, how can I know that total number of...
4
by: Rob T | last post by:
I have a small VB program that has a printing module...very simple....and works great. However, If I try to print to a generic printer, I get the following error: "The data area passed to a...
6
by: Bill | last post by:
Hi I am trying to get my listbox items to print if they stream past the one page mark. my code is working for one page of information (if the e.hasmorepages) is not there. But I am having...
3
by: islay | last post by:
Hello, I'm trying to print more than one page using the PrintDocument object. I set "e.HasMorePages = True" after completeing the first page in the "PrintDocument1_PrintPage" subroutine, and...
3
by: Richard MSL | last post by:
I have an application that prints documents that it creates. It uses what I believe is a standard .NET way of doing so, like this: PrintDocument pd = new PrintDocument(); pd.PrintPage += new...
2
by: tghamm | last post by:
Ok, so this is driving me mad. For some reason, regardless of the value of ev.hasmorepages, the printoducment1_printpage gets called twice for every page. So, I print 2 pages of data on one page,...
2
by: deepakfordotnet | last post by:
Hi, First of all let me confess that I could not get the solution to the same problem from an earlier post Printing :by Mr.Richard MSL (dated September 24th 2006) working. (Replied by Mr.Walter...
0
it0ny
by: it0ny | last post by:
Hi guys, thanks I am fairly new to this forum so I hope I chose the right place to post this question. I try to make my program printout a deposit's report. I created a class to store the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.