我有一个VB.NET WinForms应用程序WebBrowser控件。我能够设置从code和打印默认打印机,而不提示用户。然而,也有一个打印按钮,显示PrintDialog类。如果这个动作是先完成的页面将打印。然后,如果我尝试以编程方式打印版本(重新设置默认打印机到其他打印机)的将打印在PrintDialog类中选择的最后一个打印机即使我重新设置默认值,看看默认打印机在Windows中被改变。
任何想法?
它工作正常,除非ShowPrintDialog具有先选择一台打印机。一旦出现似乎总是使用该打印机无论我做什么。
对于每个将为strPrinter在PrinterSettings.InstalledPrinters
如果strPrinter.Contains(我的打印机),然后
wScript.SetDefaultPrinter(将为strPrinter)
结束如果
下一个
browser.Print()
解决方案
我创造了什么也没有它的形式。启动/关闭该表单的操作使得它到正确的打印机......我不知道为什么这样的作品,但必须有一些功能可以被称为模拟任何行动正在发生在那里。
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.