C
Chris Fink
I am using the webbrowser control in a winforms app. It is an unattended
app, so as soon as the event "form1_shown" is fired the webbrowser control
loads a url and then wires the print event as such, prints the document, and
is then supposed to exit the app.
webBrowser1.DocumentCompleted += new
WebBrowserDocumentCompletedEventHandler(PrintDocument);
the print document event prints the document (without a print dialog) after
the webbrowser control is loaded. I've noticed that the actual print does
not take place until this event code is run and control is returned form1.
My question is, I want to call Application.Exit after printing is complete,
but I do not see an event available in the webbrowser control. How do I exit
out of the app after the printing is done? Note, If I place the
application.exit() within the print event at the end, the application always
exits before the document is printed.
private void PrintDocument(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
try
{
// Print the document now that it is fully loaded.
((System.Windows.Forms.WebBrowser)sender).Print();
// Dispose the WebBrowser now that the task is complete.
((System.Windows.Forms.WebBrowser)sender).Dispose();
}
catch (Exception ex)
{
}
}
app, so as soon as the event "form1_shown" is fired the webbrowser control
loads a url and then wires the print event as such, prints the document, and
is then supposed to exit the app.
webBrowser1.DocumentCompleted += new
WebBrowserDocumentCompletedEventHandler(PrintDocument);
the print document event prints the document (without a print dialog) after
the webbrowser control is loaded. I've noticed that the actual print does
not take place until this event code is run and control is returned form1.
My question is, I want to call Application.Exit after printing is complete,
but I do not see an event available in the webbrowser control. How do I exit
out of the app after the printing is done? Note, If I place the
application.exit() within the print event at the end, the application always
exits before the document is printed.
private void PrintDocument(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
try
{
// Print the document now that it is fully loaded.
((System.Windows.Forms.WebBrowser)sender).Print();
// Dispose the WebBrowser now that the task is complete.
((System.Windows.Forms.WebBrowser)sender).Dispose();
}
catch (Exception ex)
{
}
}