2014-05-06 107 views
-1

我从msdn复制和粘贴代码打印,我不知道什么是“PrintDocument的”在该行 :为什么我不能用WebBrowser控件

webBrowserForPrinting.DocumentCompleted += 
     new WebBrowserDocumentCompletedEventHandler(PrintDocument); 

我将其更改为“printDocument1 “但它告诉我:

printDocument1是一个‘场’,而是使用类似‘我的形式方法’

- printPreviewControl1 
- printDocument1 
- pageSetupDialog1 
+0

'PrintDocument'是一个方法(函数)。 'printDocument1'是一个字段(可能是一个控件)。 – gunr2171

回答

0

您需要还包括从样品PrintDocument()方法:

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

现在它说:无法投入'System.Drawing.Printing.PrintDocument'类型的对象来键入'System.Windows.Forms.WebBrowser'。 –

+0

在那一行:((WebBrowser)sender).Print(); –

+0

确保其他部分仍然是:'webBrowserForPrinting.DocumentCompleted + = new WebBrowserDocumentCompletedEventHandler(PrintDocument);' –

相关问题