I am creating a new Web Browser control in my windows forms project to print some formatted HTML. The user does not need to see the control since it is simply printing a specially formatted version of the page that they are on.
This is the process of printing I am currently using.
internal void PrintQuestion(SessionPart SessionPart)
{
WebBrowser wbForPrinting = new WebBrowser(); //<-- Undisposed local
wbForPrinting.Parent = this;
wbForPrinting.DocumentCompleted += wbForPrinting_DocumentCompleted;
wbForPrinting.DocumentText = string.Format(DOCUMENT_HTML, SessionPart.Session.Course.Product.Name, HtmlFormatter.GetPrintableQuestion(SessionPart));
}
void wbForPrinting_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
// Print the document now that it is fully loaded.
((WebBrowser)sender).ShowPrintPreviewDialog();
}
I can not dispose of the WebBrowser right after the show print preview dialog because that would destroy the object I am attempting to print. There does not seem to be an event or way of determining that the user is done with the WebBrowser (either by finishing the print, or canceling the preview). This is the last piece of this project and my time is running out, I do not want to leave an undisposed local.
have you tried this
Printing with Web Browser Control and Disposing afterwards