为什么即使我取消对话框,Word 2010 仍会打印?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,我使用旧版本的代码来调试应用程序,其中该行
未包含在
else
块中。一旦我调试了代码的正确版本,打印对话框就会按预期运行。抱歉打扰...
Sorry, I was using an old version of the code to debug the application, where the line
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 ...