473,386 Members | 1,795 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,386 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 14546
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
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...

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.