c# - WebBrowser.Print() 等到完成。 。网

标签 c# .net vb.net printing browser

我在 VB.NET 中使用 WebBrowser 控件并调用 Print() 方法。我正在使用 PDF 打印机打印出来,当调用 Print() 时,它不会立即启动(它会等到完成整个 Sub 或 block 的运行代码。

我需要确保我正在打印的文件也已完成并继续处理此文件,因此,我想按需打印并了解操作完成时的一些状态。我试过使用 printDocument 和 process 但运气不好。

有人有什么想法吗?

最佳答案

检查底层非托管 WebBrowser 对象的 PrintTemplateTeardown 事件。有时该事件会被多次触发,但希望这会为您指明正确的方向。您需要添加对 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

关于c# - WebBrowser.Print() 等到完成。 。网,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2470060/

相关文章:

c# - 你能为 Visual C#.NET 解决方案推荐一个 .cvsignore 文件吗?

c# - 在 Logging 中使用 StackFrame 和 MethodBase 的区别

c# - VB中的&符号是什么?

c# - 我无法让 ProcessCmdKey 工作?

c# - Google chrome 在后续调用中丢失 MVC Auth Cookie(Set-Cookie 指令)

c# - 将 c# 代码文件转换为一个 html 文件?

ASP.NET Global.asax - bundle 中的 IE 条件样式表

c# - 静态方法的依赖注入(inject)

c# - 如何将 DbSet 转换为 ObservableCollection

vb.net - 查找内存不足的照片