Impression du contenu du contrôle WebBrowser
Question
Je suis absolument nouveau dans l'impression sous .NET. Je voudrais imprimer une page qui est affichée dans le contrôle WebBrowser. Comment je fais ça?
La solution
MSDN a publié un article à ce sujet. Toutefois, leur exemple de code montre comment utiliser le contrôle WebBrowser pour imprimer une page Web sans l'afficher. :
Comment: imprimer avec un contrôle WebBrowser
Le code c #:
private void PrintHelpPage()
{
// Create a WebBrowser instance.
WebBrowser webBrowserForPrinting = new WebBrowser();
// Add an event handler that prints the document after it loads.
webBrowserForPrinting.DocumentCompleted +=
new WebBrowserDocumentCompletedEventHandler(PrintDocument);
// Set the Url property to load the document.
webBrowserForPrinting.Url = new Uri(@"\\myshare\help.html");
}
private void PrintDocument(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
// Print the document now that it is fully loaded.
((WebBrowser)sender).Print();
// Dispose the WebBrowser now that the task is complete.
((WebBrowser)sender).Dispose();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow