WebBrowser.Print()等待,直到完成。 。净WebBrowser、Print

2023-09-03 07:41:56 作者:鱼的第八秒是忘记

我正在使用VB.NET WebBrowser控件并调用print()方法。我打印出使用PDF打印机和打印时()被调用它不立即拉开序幕(它等待,直到它已完成运行code整个Sub或块。

I am using a WebBrowser control in VB.NET and calling the Print() method. I am printing out using a PDF printer and when Print() is called it is not immediately kicked off (it waits until it has completed running code for the entire Sub or block.

我要确保我打印过的文件是完整的,并继续进程这个文件,所以,我想按需印刷,并获得当操作完成的一些状态。我曾尝试usign的PrintDocument和处理没有运气。

I need to make sure the file I am printing too is complete and continue process with this file, therefore, I would like to print on demand and get some status of when the operation is complete. I have tried usign printDocument and process without luck.

任何人有什么想法?

推荐答案

检查出潜在的非托管WebBrowser对象的 PrintTemplateTeardown 事件。有时,该事件被解雇了多次,但希望这将指向你在正确的方向。你需要添加一个引用到 Microsoft Internet控制

Check out the PrintTemplateTeardown event of the underlying unmanaged WebBrowser object. Sometimes that event gets fired multiple times but hopefully this will point you in the right direction. You need to add a reference to Microsoft Internet Controls.

Private Sub Print()
    AddHandler DirectCast(WebBrowser1.ActiveXInstance, SHDocVw.WebBrowser).PrintTemplateTeardown, AddressOf PrintDone
    WebBrowser1.Print()
End Sub
Private Sub PrintDone(ByVal obj As Object)
    Trace.WriteLine("printed")
    RemoveHandler DirectCast(WebBrowser1.ActiveXInstance, SHDocVw.WebBrowser).PrintTemplateTeardown, AddressOf PrintDone
End Sub