更新时间:2023-12-06 13:51:58
我创造了什么也没有它的形式。启动/关闭该表单的操作使得它到正确的打印机......我不知道为什么这样的作品,但必须有一些功能可以被称为模拟任何行动正在发生在那里。
I have a WebBrowser control in a VB.NET WinForms app. I am able to set the default printer from code and print without prompting the user. However, there is also a print button that shows the PrintDialog. If this action is done first the page will print. Then if I try to programmatically print later (again setting the default printer to some other printer) the it will print to the last printer selected in the PrintDialog box even though I am resetting the default and see the default printer being changed in Windows.
Any ideas?
It works fine unless ShowPrintDialog has a printer chosen first. Once that occurs it seems to always use that printer no matter what I do.
For Each strPrinter In PrinterSettings.InstalledPrinters
If strPrinter.Contains("My Printer") Then
wScript.SetDefaultPrinter(strPrinter)
End If
Next
browser.Print()
I created a form with nothing on it. The action of launching/closing this form made it go to the right printer... I have no idea why that works, but there must be some function that could be called to simulate whatever action is taking place there.