Printing a multi-page document

J

Jason James

Hi all,

I have an application that needs to print numerous
documents of different styles (either to the printer
or print preview dialog).

I have selected which document type to print by
using a select statement in the the

PrintDocument.PrintPage

event handler. This appears to work very well until
I try and print a document with multiple pages.

When I set

e.HasMorePages = TRUE,

the event fires the PrintPage event but the subroutine
that handles the actual rendering is not called a second time.

If I move the rendering code into the PrintPage event
handler (so only one format of page can be printed) then
everything seems to work OK.

Here is all of the code that is containted in the

PrintDocument.PrintPage event handler

nThisLabel = 0
' LabelType is an enum.
Select Case LabelType
Case LabelTypes.AlphaSnap
PrintOutlets(e)
Case LabelTypes.AlphaSnap12Port
PrintAlphaSnap12Port(e)
Case LabelTypes.AlphaSnap16Port
PrintAlphaSnap16Port(e)
Case LabelTypes.AlphaSnap24Port
PrintAlphaSnap24Port(e)
End Select


Is there a better way to decide which document to render
that will not cause this unwanted functionality in my
program and multi-page documents will be printed correctly?

Many thanks,

Jason.
 
H

Herfried K. Wagner [MVP]

* Jason James said:
I have an application that needs to print numerous
documents of different styles (either to the printer
or print preview dialog).

I have selected which document type to print by
using a select statement in the the

PrintDocument.PrintPage

event handler. This appears to work very well until
I try and print a document with multiple pages.

When I set

e.HasMorePages = TRUE,

the event fires the PrintPage event but the subroutine
that handles the actual rendering is not called a second time.

If I move the rendering code into the PrintPage event
handler (so only one format of page can be printed) then
everything seems to work OK.

Here is all of the code that is containted in the

PrintDocument.PrintPage event handler

nThisLabel = 0
' LabelType is an enum.
Select Case LabelType
Case LabelTypes.AlphaSnap
PrintOutlets(e)
Case LabelTypes.AlphaSnap12Port
PrintAlphaSnap12Port(e)
Case LabelTypes.AlphaSnap16Port
PrintAlphaSnap16Port(e)
Case LabelTypes.AlphaSnap24Port
PrintAlphaSnap24Port(e)
End Select


Is there a better way to decide which document to render
that will not cause this unwanted functionality in my
program and multi-page documents will be printed correctly?

Are you sure 'LabelType' is set corretly? How/where do you set the
label type?
 
J

JJ

Hi Herfried ,

LabelType is a public variable of type LabelTypes, which is an
enumerated type. It is set through the users' interaction with
the GUI. When I step through the code the select statement
appears to work fine, it just doe not call the appropriate
subroutine.

Hope this helps,

Jason
 
J

JJ

The problem is sorted. The variable nThisLabel was being
reset in the PrintPage event handler and it shouldn't have
been. This counter keeps track of the number of elements
printed and should only have been reset once all of the pages
of the document were printed.

Thanks for your help,

Jason.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top