GUI在.net中使用PrintDialog和PrintPreviewDialog时锁定

EMa*_*x84 5 .net c# printing user-interface multithreading

我正在使用.net的PrintPreviewDialog,每当它生成预览时,它会在后台锁定我的GUI并使其看起来像已经崩溃直到预览完成.看到弹出的.net页面进度窗口不是一个对话框,可以选择背景,然后以半绘制的锁定方式进入前面.当用户单击预览对话框上的实际"打印"按钮时,以及刚运行PrintDocument.Print()时,也会发生这种情况.有一种简单的方法可以修改以下代码,以便在用户等待.net绘制打印页面时停止GUI挂起:

//just showing a preview, hangs up background GUI on generating the preview
// and when user prints straight from the preview
this.printPreviewDialog.ShowDialog(this);

//just trying to print a .net PrintDocument class, GUI hangs in background
// when .net is drawing the pages
this.printDocument.Print();
Run Code Online (Sandbox Code Playgroud)

gco*_*res 1

如果这些方法花费很长时间,您可能应该在不同的线程中调用这些方法。研究一下BackgroundWorker的使用来帮助你。

另外,这可能是因为 Windows 打印机而不是您的代码(您是否使用网络打印机?如果是,请更改为虚拟打印机,看看是否会改变任何内容)。