Search code examples
.netprintingdelphi-prismprintdocument

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,


Solution

  • HasMorePages is a boolean property of the PrintPageEventArgs you receive as a parameter of the event. You set it to True after printing the current page if there are more pages to be printed, or False if the current page is the last one.

    Events are always called for you by something in the framework, and are never supposed to be called directly by you. They are events, which mean they're dispatched to tell you that something has happened and give you a chance to respond or react.

    If you set it to True, the PrintPage event is called again automatically; you do not call it yourself. (That's exactly what the MSDN documentation says: If you set it to true, the printpage event is called again. It doesn't say you'll need to call it again - it says is called again.)

    ev.HasMorePages := DoYouHaveMorePagesToPrint;
    

    For a VB.NET example of the event and how to use ev.HasMorePages, see the MSDN documentation for PrintDocument. For info on PrintPageEventArgs, see this MSDN page, which has a link to the members of PrintPageEventArgs (including HasMorePages).