Printing WebBrowser control content

后端 未结 1 853
梦谈多话
梦谈多话 2021-01-14 01:52

I\'m absolutely new to printing in .NET. I would like to print a page that is displayed in WebBrowser control. How do I do that?

相关标签:
1条回答
  • 2021-01-14 02:42

    MSDN has an article about this, however their code example demonstrates how use the WebBrowser control to print a Web page without displaying it. :

    How to: Print with a WebBrowser Control

    The c# code:

    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();
    }
    
    0 讨论(0)
提交回复
热议问题