次の方法で共有


方法 : WebBrowser コントロールを使用して印刷する

更新 : 2007 年 11 月

次のコード例は、WebBrowser コントロールを使用して、Web ページを表示しないで印刷する方法を示しています。

使用例

Private Sub PrintHelpPage()

    ' Create a WebBrowser instance. 
    Dim webBrowserForPrinting As New WebBrowser()

    ' Add an event handler that prints the document after it loads.
    AddHandler webBrowserForPrinting.DocumentCompleted, New _
        WebBrowserDocumentCompletedEventHandler(AddressOf PrintDocument)

    ' Set the Url property to load the document.
    webBrowserForPrinting.Url = New Uri("\\myshare\help.html")

End Sub

Private Sub PrintDocument(ByVal sender As Object, _
    ByVal e As WebBrowserDocumentCompletedEventArgs)

    Dim webBrowserForPrinting As WebBrowser = CType(sender, WebBrowser)

    ' Print the document now that it is fully loaded.
    webBrowserForPrinting.Print()
    MessageBox.Show("print")

    ' Dispose the WebBrowser now that the task is complete. 
    webBrowserForPrinting.Dispose()

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

コードのコンパイル方法

必要な条件は次のとおりです。

  • System アセンブリおよび System.Windows.Forms アセンブリへの参照。

参照

処理手順

方法 : WebBrowser コントロールで URL に移動する

方法 : Windows フォーム アプリケーションに Web ブラウザの機能を追加する

方法 : Windows フォーム アプリケーションで HTML ドキュメントビューアを作成する

概念

WebBrowser セキュリティ

参照

WebBrowser

Print

Url

WebBrowser コントロールの概要