简体   繁体   English

Hasmorepages PrintPageEventArgs属性到底能做什么?

[英]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. 我试图了解Hasmorepages PrintPageEventArgs属性是什么,为什么要使用它以及它如何工作。

MSDN Library doesn't really have a good explanation. MSDN Library并没有很好的解释。 All they say is that if you set it to true, printpage event is called again. 他们只说如果将其设置为true,则将再次调用printpage事件。 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? 这是否意味着事件在其自身上循环而没有离开或离开,然后再次调用自身或依靠您再次调用printpage事件?

I am just trying to understand PrintPageEventArgs.hasmorepages property. 我只是想了解PrintPageEventArgs.hasmorepages属性。 Any hints or help will be greatly appreciated. 任何提示或帮助将不胜感激。

Thank you, 谢谢,

It is not a property of a PrintDocument, it is a property of PrintPageEventArgs. 它不是PrintDocument的属性,而是PrintPageEventArgs的属性。 An instance of which gets passed to your PrintPage event handler. 其实例将传递到您的PrintPage事件处理程序。

The way the PrintController and PrintDocument classes work is heavily affected by the way printing is implemented in Windows. Windows中实现打印的方式严重影响PrintController和PrintDocument类的工作方式。 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(). 打印机驱动程序一次处理一页,底层的winapi函数是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. 然后,EndPage()winapi函数完成页面并将其提交到后台打印程序。

It might help to diagram the calls made while a 3 page document is printed: 可能有助于绘制打印3页文档时的调用图:

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. 现在应该清楚了,通过分配e.HasMorePage = true,可以让PrintController继续触发PrintPage事件。 It is up to you to paginate your document and render the content of the correct page in your PrintPage event handler. 由您来分页文档并在PrintPage事件处理程序中呈现正确页面的内容。 You'll need the BeginPrint event to, say, set your internal page counter to 0. 您将需要BeginPrint事件,例如,将内部页面计数器设置为0。

HasMorePages is a boolean property of the PrintPageEventArgs you receive as a parameter of the event. HasMorePages是您作为事件参数收到的PrintPageEventArgs的布尔属性。 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. 如果要打印更多页面,则在打印当前页面后将其设置为True如果当前页面为最后一页,则将其设置为False

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; 如果将其设置为True ,则会自动再次调用PrintPage事件。 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 .) (这正是MSDN文档所说的:如果将其设置为true,则将再次调用 printpage事件。它并不表示您需要再次调用它 -它会再次 调用 。)

ev.HasMorePages := DoYouHaveMorePagesToPrint;

For a VB.NET example of the event and how to use ev.HasMorePages , see the MSDN documentation for PrintDocument . 有关该事件的VB.NET示例以及如何使用ev.HasMorePages ,请参见PrintDocumentMSDN文档 For info on PrintPageEventArgs , see this MSDN page , which has a link to the members of PrintPageEventArgs (including HasMorePages ). 有关PrintPageEventArgs信息,请参见此MSDN页面 ,该页面具有指向PrintPageEventArgs成员 (包括HasMorePages )的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM