簡體   English   中英

打印 WebBrowser 控件內容

[英]Printing WebBrowser control content

我對在 .NET 中打印完全陌生。 我想打印一個顯示在 WebBrowser 控件中的頁面。 我怎么做?

MSDN 有一篇關於此的文章,但是他們的代碼示例演示了如何使用 WebBrowser 控件打印 Web 頁面而不顯示它。

如何:使用 WebBrowser 控件進行打印

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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM