WebBrowser控件将不会从C#打印 [英] WebBrowser control won't print from C#

查看:114
本文介绍了WebBrowser控件将不会从C#打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForms应用程序的加载XML将其转化为HTML / CSS WebBrowser控件。看上去很美,如果我只是想查看它有或定期的浏览器。

I've got a WebBrowser control on a WinForms app that is loading XML which is converted to HTML/CSS. Looks beautiful if I just want to view it there or in a regular browser.

当窗体加载,它应该导航到该文件,然后在OnDocumentCompleted事件触发,它应该在注册表中设置页眉,页脚和默认打印机名称,然后调用打印()为用户指定然而许多副本。

When the form loads, it's supposed to navigate to the file, then when the OnDocumentCompleted event fires, it should set the header, footer, and default printer name in the registry, then call Print() for however many copies the user has specified.

我已经通过调试器中运行它,它调用webBrowser.Print()正确的数字在OnDocumentCompleted事件时间。没有什么是空不应该,可见是WebBrowser控件真实的,因为是AllowNavigation。是的,打印机已开启,并且可通过网络。完全相同的代码工作其他地方的项目,但不是在这里。

I've run it through the debugger, and it's calling webBrowser.Print() the correct number of times in the OnDocumentCompleted event. Nothing is null that shouldn't be, Visible is true on the WebBrowser control, as is AllowNavigation. And yes, the printer is turned on and reachable over the network. The exact same code works elsewhere in the project, but not here.

还有什么可能会导致这地狱般的控制,以忽略我的打印命令?

What else could be causing this hellish control to ignore my Print commands?

在理想情况下,我想整个事情被隐藏关屏,因为这意味着使用Windows计划程序来运行,并且用户应该永远不会看到它。我读过的控件需要可见,虽然如此,直到我出这第一扭结,可以等待。

Ideally, I'd like the whole thing to be hidden off-screen, as this is meant to run using Windows Scheduler, and the users should never see it. I've read that the control needs to be visible, though, so until I work out this first kink, that can wait.

修改 :我OnDocumentCompleted事件处理程序的最后两行的DialogResult设置为OK和关闭的形式。卸下调用close()让它打印,所以我猜它没能打印后台处理程序被关闭之前的形式和WebBrowser控件的处置。

EDIT: The last two lines of my OnDocumentCompleted event handler set the DialogResult to OK and closed the form. Removing the call to Close() let it print, so I'm guessing it didn't get to the print spooler before the form was closed and the WebBrowser control was disposed.

仅仅设置任意时间限制在关闭之前等待短,有没有什么办法,当它完成打印分辨?

Short of just setting an arbitrary time limit to wait before closing, is there any way to tell when it is done printing?

推荐答案

原来是一个时机的问题,与窗体关闭之前就可以在文档发送到后台打印程序。我结束了添加一个定时器的形式,将其设置为30秒,有它的Tick()事件关闭窗体。凡先前关闭的形式,它现在只是调用closeTimer.Start()。

Turned out to be a timing issue, with the form being closed before it could send the document to the print spooler. I wound up adding a Timer to the form, setting it for 30 seconds, and having it's Tick() event close the form. Where it was closing the form previously, it now just calls closeTimer.Start().

这篇关于WebBrowser控件将不会从C#打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆