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