如果打印机对话框取消,则不打印?
如果我运行此代码,并按 PrintDialog 上的“取消”,它仍然会打印。如何判断使用是否按下了取消?
PrintDocument document = new PrintDocument();
PrintDialog dialog = new PrintDialog();
dialog.ShowDialog();
document.PrinterSettings = p.PrinterSettings;
document.Print();
附录
WebBrowser w = new WebBrowser();
w.ShowPrintDialog(); //.ShowPrintDialog returns a void, how can I deal with this?
If I run this code, and press cancel on the PrintDialog, it still prints. How can I tell if the use pressed cancel?
PrintDocument document = new PrintDocument();
PrintDialog dialog = new PrintDialog();
dialog.ShowDialog();
document.PrinterSettings = p.PrinterSettings;
document.Print();
Addendum
WebBrowser w = new WebBrowser();
w.ShowPrintDialog(); //.ShowPrintDialog returns a void, how can I deal with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以检查 ShowDialog 方法的结果:
You can check the result of the ShowDialog method:
ShowDialog 返回对话框结果枚举。要么确定,要么取消。
ShowDialog returns a dialog result enumeration. It will either be OK, or Cancel.
上面的答案对于 是正确的
System.Windows.Forms.PrintDialog
。但是,如果您不构建Forms
应用程序,则您将使用的PrintDialog
是System.Windows.Controls.PrintDialog
。这里,ShowDialog
返回一个bool?
:The answers above are correct for
System.Windows.Forms.PrintDialog
. However, if you're not building aForms
application, thePrintDialog
you will use isSystem.Windows.Controls.PrintDialog
. Here,ShowDialog
returns abool?
: