0

我正在我的 windows 窗体项目中创建一个新的 Web 浏览器控件来打印一些格式化的 HTML。用户不需要查看控件,因为它只是打印他们所在页面的特殊格式版本。

这是我目前正在使用的打印过程。

    internal void PrintQuestion(SessionPart SessionPart)
    {
        WebBrowser wbForPrinting = new WebBrowser(); //<-- Undisposed local
        wbForPrinting.Parent = this;
        wbForPrinting.DocumentCompleted += wbForPrinting_DocumentCompleted;
        wbForPrinting.DocumentText = string.Format(DOCUMENT_HTML, SessionPart.Session.Course.Product.Name, HtmlFormatter.GetPrintableQuestion(SessionPart));
    }

    void wbForPrinting_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        // Print the document now that it is fully loaded.
        ((WebBrowser)sender).ShowPrintPreviewDialog();
    }

我无法在显示打印预览对话框之后立即处理 WebBrowser,因为这会破坏我尝试打印的对象。似乎没有事件或方法可以确定用户是否已使用 WebBrowser(通过完成打印或取消预览)。这是这个项目的最后一部分,我的时间不多了,我不想离开一个闲散的当地人。

4

1 回答 1

0

你试过这个吗

void wbForPrinting_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    // Print the document now that it is fully loaded.
    ((WebBrowser)sender).ShowPrintPreviewDialog();
    // Dispose the WebBrowser now that the task is complete. 
    ((WebBrowser)sender).Dispose();
}

使用 Web 浏览器控件进行打印并随后进行处理

于 2012-08-02T20:16:40.780 回答