Domanda

Sono assolutamente nuovo alla stampa in .NET. Vorrei stampare una pagina che viene visualizzata nel controllo WebBrowser. Come posso farlo?

È stato utile?

Soluzione

MSDN ha un articolo a riguardo, tuttavia il loro esempio di codice dimostra come utilizzare il controllo WebBrowser per stampare una pagina Web senza visualizzarla. :

Procedura: stampare con un controllo WebBrowser

Il codice 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();
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top