【问题标题】:Printing WebBrowser control content打印 WebBrowser 控件内容
【发布时间】:2010-10-11 05:52:21
【问题描述】:

我对 .NET 中的打印完全陌生。我想打印一个显示在 WebBrowser 控件中的页面。我该怎么做?

【问题讨论】:

    标签: c# .net printing


    【解决方案1】:

    MSDN 有一篇关于此的文章,但是他们的代码示例演示了如何使用 WebBrowser 控件打印网页而不显示它。 :

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

    【讨论】:

    • 如何在 asp.net 项目中使用 WebBrowser 类?
    • 我不太确定你的意思是什么? WebBrowser 类用于在 WinForms 应用程序中显示网页。我假设你有一个 ASP.NET 网站 (WebForms) 并且你想打印一个页面?您应该为此使用 JavaScript,例如:window.print()
    • 我忘记添加示例代码:打印此页!
    • @RuudKok 知道您是否可以设置打印机名称和设置,而不仅仅是使用默认打印机打印?
    • 请问如何在没有printer dialogsave As的情况下直接打印到特定的网络打印机
    猜你喜欢
    • 1970-01-01
    • 2010-11-20
    • 1970-01-01
    • 2010-12-25
    • 1970-01-01
    • 2020-03-21
    • 2010-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多