为什么即使我取消对话框,Word 2010 仍会打印?

发布于 2024-11-16 13:23:28 字数 974 浏览 3 评论 0原文

我正在使用 Visual Studio 2010 Office 工具“远程控制”Word 2010。这效果很好,我还可以打印我创建的文档。但是,当我显示 Word 的打印对话框时,即使按取消按钮也会打印文档。为什么会这样?我该如何正确地对按下取消按钮做出反应?

我的代码如下:

public void Print(string printerName, bool showPrintDialog)
{
    if (m_wordApp == null || m_wordDoc == null)
        throw new InvalidOperationException("...");

    object missing = System.Type.Missing;
    object varTrue = true;

    if (printerName != null)
        m_wordApp.ActivePrinter = printerName;

    if (showPrintDialog)
    {
        Word.Dialog varDlg = m_wordApp.Application.Dialogs[Word.WdWordDialog.wdDialogFilePrint];
        varDlg.Show(ref missing);
    }
    else
    {
        m_wordDoc.PrintOut(ref varTrue, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing);
    }
}

I'm using the Visual Studio 2010 Office Tools to "remote control" Word 2010. This works great, I can also print the document I create. However, when I show Word's print dialog, the document is printed even if I press the cancel button. Why is that so and how can I properly react to the cancel button being pressed?

My code is as follows:

public void Print(string printerName, bool showPrintDialog)
{
    if (m_wordApp == null || m_wordDoc == null)
        throw new InvalidOperationException("...");

    object missing = System.Type.Missing;
    object varTrue = true;

    if (printerName != null)
        m_wordApp.ActivePrinter = printerName;

    if (showPrintDialog)
    {
        Word.Dialog varDlg = m_wordApp.Application.Dialogs[Word.WdWordDialog.wdDialogFilePrint];
        varDlg.Show(ref missing);
    }
    else
    {
        m_wordDoc.PrintOut(ref varTrue, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

燕归巢 2024-11-23 13:23:28

抱歉,我使用旧版本的代码来调试应用程序,其中该行

m_wordDoc.PrintOut(ref ...);

未包含在 else 块中。一旦我调试了代码的正确版本,打印对话框就会按预期运行。

抱歉打扰...

Sorry, I was using an old version of the code to debug the application, where the line

m_wordDoc.PrintOut(ref ...);

was not wrapped in an else block. Once I debugged the correct version of my code, the print dialog behaved as expected.

Sorry to interrupt ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文