如果打印机对话框已取消,则不打印?

soo*_*ise 1 c# printing printdialog

如果我运行此代码,并在PrintDialog上按取消,它仍会打印.如何判断使用是否取消?

PrintDocument document = new PrintDocument();
PrintDialog dialog = new PrintDialog();

dialog.ShowDialog();
document.PrinterSettings = p.PrinterSettings;
document.Print();
Run Code Online (Sandbox Code Playgroud)

附录

WebBrowser w = new WebBrowser();
w.ShowPrintDialog(); //.ShowPrintDialog returns a void, how can I deal with this?
Run Code Online (Sandbox Code Playgroud)

Joh*_*ner 7

您可以检查ShowDialog方法的结果:

if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
   //Print
}
Run Code Online (Sandbox Code Playgroud)

  • 我可以用WebBrowser.ShowPrintDialog做什么?它返回一个void而不是DialogResult. (2认同)