Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
406 views
in Technique[技术] by (71.8m points)

.net - What does Hasmorepages PrintPageEventArgs property do exactly?

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...