检测时,一个成功的PrintDocument打印(不只是previewed) [英] Detect when a PrintDocument successfully prints (not just previewed)

查看:386
本文介绍了检测时,一个成功的PrintDocument打印(不只是previewed)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做使用<一个有些自定义打印href="http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx">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 以完全相同的方式进入<构建的href="http://msdn.microsoft.com/en-us/library/system.windows.forms.print$p$pviewdialog.aspx">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.

推荐答案

好了,我居然设法想出解决办法喽,使用<一个href="http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.printcontroller.aspx">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 ();
}

这篇关于检测时,一个成功的PrintDocument打印(不只是previewed)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆