检测时,一个成功的PrintDocument打印(不只是previewed)PrintDocument、previewed

由网友(地心侵略者)分享简介:我正在做使用PrintDocument在我的应用程序。我有当我们的项目成功打印记录的要求。本来我做到了这一点的东西,如:I'm doing some custom printing using a PrintDocument in my application. I have a requirement of log...

我正在做使用PrintDocument在我的应用程序。我有当我们的项目成功打印记录的要求。本来我做到了这一点的东西,如:

I'm doing some custom printing using a PrintDocument in my application. I have a requirement of logging when our items are successfully printed. I originally achieved this with something like:

 print_doc.EndPrint += (o,e) => printed_callback ();

为了使我的 printed_callback 被调用时,打印完成。然而,现在我加入preVIEW的支持,我路过一个的PrintDocument 以完全相同的方式进入Print$p$pviewDialog.这样做可以让 EndPrint 事件所需的preVIEW打印输出的初始渲染后调用。

To make my printed_callback get invoked when a print finished. However, now that I'm adding preview support, I'm passing a PrintDocument constructed in exactly the same way into a PrintPreviewDialog. Doing so causes the EndPrint event to be invoked after the initial rendering of the printout needed for the preview.

这样一来,即使用户点击preVIEW,然后就关闭了preVIEW,我们的记录code被调用。

As a result, even if a user clicks "Preview" and then just closes the preview, our logging code gets invoked.

有关如何在真正的打印输出和一个preVIEW打印区分有什么建议?不幸的是,我不能只是没有钩到 EndPrint 的PrintDocument 传递给打印previewDialog ,因为用户可以点击打印按钮,在preVIEW对话框,并触发打印输出。

Any suggestions for how to differentiate between a real printout and a "preview print" ? Unfortunately, I can't just not hook up to EndPrint for the PrintDocument passed to the PrintPreviewDialog since the user may click the "Print" button in the preview dialog and trigger a printout.

推荐答案

好了,我居然设法想出解决办法喽,使用PrintDocument.PrintController物业,并检查是preVIEW控制器属性。我最后的codeD结束如下:

Ok, so I actually managed to figure this out myself, using the PrintDocument.PrintController property, and checking the IsPreview property of the controller. My final coded ended up as follows:

doc.EndPrint += (o,e) =>
{
    if (doc.PrintController.IsPreview)
        return;

    print_callback ();
}
阅读全文

相关推荐

最新文章