Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to understand what Hasmorepages PrintPageEventArgs property is, why would you use it and how does it work.

MSDN Library doesn't really have a good explanation. All they say is that if you set it to true, printpage event is called again. Is that mean the event loops on itself without leaving or leaves and calls itself again or relies on you to call the printpage event again?

I am just trying to understand PrintPageEventArgs.hasmorepages property. Any hints or help will be greatly appreciated.

Thank you,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
399 views
Welcome To Ask or Share your Answers For Others

1 Answer

It is not a property of a PrintDocument, it is a property of PrintPageEventArgs. An instance of which gets passed to your PrintPage event handler.

The way the PrintController and PrintDocument classes work is heavily affected by the way printing is implemented in Windows. A core implementation detail is that it is page-based. The printer driver deals with one page at a time, the underlying winapi function is StartPage(). Anything rendered to the print device context ends up on one page. Then the EndPage() winapi function completes the page and submits it to the spooler.

It might help to diagram the calls made while a 3 page document is printed:

StartDoc()
    PrintDocument.BeginPrint event
    StartPage()
       PrintDocument.PrintPage event, e.HasMorePages = true
    EndPage()
    StartPage()
       PrintDocument.PrintPage event, e.HasMorePages = true
    EndPage()
    StartPage()
       PrintDocument.PrintPage event, e.HasMorePages = false
    EndPage()
    PrintDocument.EndPrint event
EndDoc()

It ought to be clear now, by assigning e.HasMorePage = true, you let the PrintController keep firing the PrintPage event. It is up to you to paginate your document and render the content of the correct page in your PrintPage event handler. You'll need the BeginPrint event to, say, set your internal page counter to 0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...