I have a WebBrowser control in a WinForms application that loads XML, which is converted to HTML / CSS. It looks beautiful if I just want to view it there or in a regular browser.
When the form loads, it should go to the file, and then, when the OnDocumentCompleted event fires, it should set the name of the header, footer and default printer name in the registry, and then call Print (), but for many copies the user specified.
I ran it through the debugger and called webBrowser.Print () the correct number of times in the OnDocumentCompleted event. Nothing is null, which should not be; Visible is true for the WebBrowser control, as is AllowNavigation. And yes, the printer is on and available over the network. The exact same code works elsewhere in the project, but not here.
What else could cause this infernal control to ignore my print commands?
Ideally, I would like all of this to be hidden behind the scenes, as this is designed to work with Windows Scheduler, and users never see it. I read that the control should be visible, however, until I work out this first bend that can wait.
EDIT . The last two lines of my OnDocumentCompleted event handler set DialogResult to OK and closed the form. Removing the Close () call allows you to print, so I assume that it did not get into the print spooler before the form was closed and the WebBrowser control was removed.
Except that you just need to set an arbitrary time limit to wait before closing, is there any way to tell when this is done?