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

本文关键字:2010 Word 打印 对话框 取消 为什么 | 更新日期: 2023-09-27 18:00:06

我正在使用Visual Studio 2010 Office Tools"远程控制"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);
    }
}

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

对不起,我使用了旧版本的代码来调试应用程序,其中行

m_wordDoc.PrintOut(ref ...);

未包装在else块中。调试了正确版本的代码后,打印对话框的行为与预期一致。

抱歉打扰了。。。