【问题标题】:Why does Word 2010 print even if I cancel the dialog?为什么即使我取消对话框,Word 2010 也会打印?
【发布时间】:2011-06-21 09:28:14
【问题描述】:

我正在使用 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);
    }
}

【问题讨论】:

    标签: c# printing office-interop office-2010


    【解决方案1】:

    对不起,我是用旧版本的代码来调试应用程序,这里的行

    m_wordDoc.PrintOut(ref ...);
    

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

    抱歉打扰了……

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-13
      • 1970-01-01
      相关资源
      最近更新 更多