Important alert: (current site time 9/18/2014 1:17:26 AM EDT)
 

winzip icon

Multi-Page Print and Preview Demo

Email
Submitted on: 4/8/2010 2:37:59 PM
By: Morgan Haueisen  
Level: Beginner
User Rating: By 9 Users
Compatibility: C#, VB.NET
Views: 14128
 
     This code provides the tools to allow you to make nice looking (multi-page) print/preview reports. I have included both the VB and C# versions. (Update: 4/07/10 - Bug Fix).

 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

1/1/2010 12:40:39 PMRishi Saxena

Perfect
(If this comment was disrespectful, please report it.)

 
1/11/2010 4:29:00 AMJorgen Levesen

Wery nice work, as expected from you. 5 globes from me.
(If this comment was disrespectful, please report it.)

 
1/12/2010 7:43:41 AMJorgen Levesen

Hi Morgan,
Got the error: "NullReferenceExecption was unhandled" in the cPrintClass 'Public Sub pBox' line: Dim tTxtHeight As Single = _Paper.Graphics.MeasureString("Morgan", _Font).Height.
What to do to get rid of this error ?

regards
Jørgen
(If this comment was disrespectful, please report it.)

 
1/19/2010 2:18:23 PMMorgan Haueisen

Jorgen, sounds like you called print before you set the graphic (.PrintPage = e).
(If this comment was disrespectful, please report it.)

 
2/5/2010 1:59:09 AMJorgen Levesen

Hi again,
This is not as easy as the vb6 version, spesially the new page call is quite confusing.
I have come that far as the print is showing in the preview box, with headings and 5 pages. It looks quite good - but when printing it only prints one page, and only the heading.
Can you think of any reason for this misbehaviour ?

Regards
Jørgen

(If this comment was disrespectful, please report it.)

 
2/5/2010 11:08:14 AMMorgan Haueisen

.NET is not very friendly when it comes printing or graphics.
I am not exactly sure what you are doing.

After calling pNewPage you must exit the sub. This is the only way that .NET will generate a new page.
Did you call pEndDoc at the end of the last page? This resets the page number.

Follow sub Report5 for how it works. There are 3 sections
1. things that happen only for the first time (page 1)
2. things that print every page
3. things that happen only on the last page.

(If this comment was disrespectful, please report it.)

 
3/28/2010 4:57:06 PMJorgen Levesen

Hi Morgan,
Just to let you know your program does not work in a 64-bits environment (like the new Win7-64). Does not get any error message though.

regards
Jorgen
(If this comment was disrespectful, please report it.)

 
3/30/2010 12:29:35 PMMorgan Haueisen

Jorgen, I have no way of testing this on Win7 but it does run on Vista 64. This is pure .Net code. It does not use any external API calls or VB Compatibility. There is no reason for it not to work.
(If this comment was disrespectful, please report it.)

 
4/9/2010 5:02:59 AMHerbert N Swearengen III

Hi Morgan,

The VB version does nothing on either Windows Vista x64 or Windows 7 x64 unless the Target CPU under Advanced Compile Options is set to x86. I don't know why this is. Just reporting what worked for me.
(If this comment was disrespectful, please report it.)

 
6/30/2010 2:13:01 PMBill K of Boston

Hi Morgan,
Sorry if question is to far afield.
What C# compiler do you recommend ?
regards,
bill
(If this comment was disrespectful, please report it.)

 
2/3/2013 10:27:39 AMShamsul Arifin

Hi,

I downloaded code from http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7586&lngWId=10
However,
I sent lot of time to get the changes the printing Paper Size, but couldn't.

Please advice how to change the Paper Size on a fly, if needed.

Thanks.
Shamsul Arifin
arifins77@yahoo.com

(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.