[Resolved][2.0]Force print in web browser control
I have a file in html that I need to open and print.
It doesn't print and it doesn't show the print dialog.
Is the problem likely to be related to the fact that I never
actually display the browser control on the screen?
I kinda want this to be done behind the scenes.
It gets the path and converts it correctly, (i.e. c://thisfolder becomes c:/thisfolder like it should)
Code:
public void PrintFile()
{
//Create a new IE control
System.Windows.Forms.WebBrowser myBrowser = new System.Windows.Forms.WebBrowser();
//Load it with file
Uri myURL = new Uri(GetDefaultPath() + "PrintThisFile.html");
myBrowser.Navigate(myURL);
myBrowser.Refresh();
//Print it
myBrowser.ShowPrintPreviewDialog();
myBrowser.Print();
//close and clean up
myBrowser.Dispose();
}//PrintFile()
Re: Force print in web browser control
Try the same thing but add the control to the form's Controls collection. If it works then you know that's the issue.
Re: Force print in web browser control
Hmmm.
It's not a form. Its a separate class.
Maybe I need a form.
Re: Force print in web browser control
DOH!
Apparently, one has to wait for the document to load before trying to print it.
So after I .Navigate, I put in a catch for the myBrowser.DocumentCompleted.
I print and dispose in the handler.