2009-03-04 18 views

答えて

6

MSDNにはこれに関する記事がありますが、WebBrowserコントロールを使用してWebページを表示せずに印刷する方法をコード例で示しています。 :

How to: Print with a WebBrowser Control

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

がどのように私はasp.netのプロジェクトでWebBrowserクラスを使用することができますか? – themis

+2

私はあなたがthemhzを意味するかどうか分かりません。 WebBrowserクラスは、WebページをWinFormsアプリケーションに表示するために使用されます。私はあなたがASP.NETのWebサイト(WebForms)を持っていると仮定し、ページを印刷したいですか?例:[window.print()](https://developer.mozilla.org/ja/DOM:window.print) – RuudKok

+1

サンプルコードを追加するのを忘れてしまった: Print this page! RuudKok

関連する問題