2009-03-04 6 views

cevap

6

MSDN, bununla ilgili bir makaleye sahiptir, ancak kod örnekleri WebBrowser denetiminin, bir Web sayfasını görüntülemeden yazdırması için nasıl kullanıldığını gösterir. :

How to: Print with a WebBrowser Control

C# kodu:

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

nasıl ben asp.net projelerinde WebBrowser sınıf kullanabilirim? – themis

+2

Onlara ne demek istediğinden emin değilim. WebBrowser sınıfı, bir WinForms uygulamasında web sayfalarını görüntülemek için kullanılır. Bir ASP.NET web sitenizin (WebForms) var olduğunu ve bir sayfa yazdırmak istediğinizi varsayalım? Bunun için JavaScript kullanmalısınız: [window.print()] (https://developer.mozilla.org/en/DOM:window.print) – RuudKok

+1

Örnek kod eklemeyi unuttum: Print this page! RuudKok