Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么即使取消对话框,Word 2010也会打印?_C#_Printing_Office Interop_Office 2010 - Fatal编程技术网

C# 为什么即使取消对话框,Word 2010也会打印?

C# 为什么即使取消对话框,Word 2010也会打印?,c#,printing,office-interop,office-2010,C#,Printing,Office Interop,Office 2010,我正在使用VisualStudio2010 Office工具来“远程控制”Word 2010。这很好,我还可以打印我创建的文档。但是,当我显示Word的“打印”对话框时,即使按下“取消”按钮,也会打印文档。为什么会这样?我如何正确地对按下取消按钮作出反应 我的代码如下: public void Print(string printerName, bool showPrintDialog) { if (m_wordApp == null || m_wordDoc == null)

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

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

m_wordDoc.PrintOut(ref ...);
未包装在
else
块中。一旦我调试了代码的正确版本,打印对话框的行为与预期的一样

对不起打扰一下