473,387 Members | 1,603 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,387 software developers and data experts.

Printing a document with multiple pages (page breaks)

5
Hello!

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
  1. PrintDocument print_tab1 = new PrintDocument();
  2.  
  3. in main():
  4.         print_tab1.PrintPage += new PrintPageEventHandler(printTab1);
  5.  
  6.         private void print_tab1_but_Click(object sender, EventArgs e)
  7.         {
  8.  
  9.             PrintDialog pd = new PrintDialog();
  10.             pd.Document = print_tab1;
  11.             if (pd.ShowDialog() == DialogResult.OK)
  12.             {
  13.                 print_tab1.Print();
  14.             }
  15.         }
  16.  
  17.         private void printTab1(Object sender, PrintPageEventArgs e)
  18.         {
  19.             e.Graphics.DrawString("page 1", new Font("Times new roman", 14, FontStyle.Bold), Brushes.Black, 60, 10);
  20.             e.HasMorePages = true;
  21.             e.Graphics.DrawString("page 2", new Font("Times new roman", 14, FontStyle.Bold), Brushes.Black, 60, 10);
  22.             e.HasMorePages = false;
  23.         }
I've seen the following post: http://www.thescripts.com/forum/thread104989.html
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.
Jan 26 '07 #1
4 14547
evll
5
So? No one can help?
Jan 28 '07 #2
kenobewan
4,871 Expert 4TB
Here is an example that may help:
Printing in C#

Note the use of hasmorepages...
Jan 28 '07 #3
evll
5
As I stated in my first post I've seen a very similar example, where a block of text is printed. But what I need is two words example - one word on the first page and the other on the second. "while" is not suitable for this. For better understanding see my simple code snippet (which doesn't work, but you'll get the idea).
Jan 29 '07 #4
evll
5
Ok. Managed to find a solution all by myself.
In case someone has the same problem in teh future:
Expand|Select|Wrap|Line Numbers
  1. int page = 1;
  2. private void printTab1(Object sender, PrintPageEventArgs e)
  3. {
  4.   if (page == 1)
  5.   {
  6.     e.Graphics.DrawString("page1", new Font("Times new roman", 14, FontStyle.Bold), Brushes.Black, 60, 10);
  7.     e.HasMorePages = true;
  8.   }
  9.   if (page == 2)
  10.   {
  11.     e.Graphics.DrawString("page2", new Font("Times new roman", 14, FontStyle.Bold), Brushes.Black, 60, 10);
  12.     e.HasMorePages = false;
  13.   }
  14.   page++;
  15. }
Jan 29 '07 #5

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

Similar topics

2
by: ray well | last post by:
hi, i need to print multiple pages on a printer. this is what i'm using now Sub Print() Dim PrintDoc As New PrintDocument AddHandler PrintDoc.PrintPage, AddressOf Me.PrintText Do While...
1
by: al jones | last post by:
I'll try again as I'm obvioulsy standing in the middle of the forest and not seeing the trees ... I didn't think I was to old to learn new trick, but this has just about convinced me otherwise. I...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
6
by: Siv | last post by:
Hi, I am getting into printing with VB.NET 2005 and want to implement the usual capability that a user can select a selection of pages. I have a report that is generated by my application that if...
4
by: m.shidoshi | last post by:
I was recently put in charge of heading up my company's website, and while I have a lot of experience on the design side of things, I'm still very new to the programming side. When I started, the...
6
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument...
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...
0
by: ben.agnoli | last post by:
I have written the below class for printing out large jpg files (1 page wide, multiple pages high) over multiple pages. The class will get instantiated multiple times at once by a windows service....
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.