私はプラス10時間でWebBrowser
プロパティに穴を開けようとしました。C#: "WebBrowserを使用してhtmlをコンソールに出力する方法"
私は単にgoogle.comに移動し、htmlコードをコンソールに出力しようとしています。これは常に私にヌル参照を与えます。
これに関連して多くの質問があり、DocumentCompleted Event Handlerが必要であるか正しく設定されていないと言われています。
だから私はまだ運がないのに、私の能力の中でこれを試しました。私はそれまで公式の例を貼り付けてコピーするまで行ったMicrosoft私はまだヌル参照を得ています!
using System;
using System.Windows.Forms;
namespace Aamanss
{
class MainClass
{
public static 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("https://www.google.com");
}
public static 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();
}
public static void Main(string[] args)
{
PrintHelpPage();
}
}
}
上記のコードの大部分は、マイクロソフトから貼り付けられたコピーです。そして、このエラー:
Gtk-Message: Failed to load module "atk-bridge"
libgluezilla not found. To have webbrowser support, you need libgluezilla installed
System.NullReferenceException: Object reference not set to an instance of an object
at System.Windows.Forms.WebBrowser.Navigate (System.Uri url) [0x0000e] in /run/build/mono/mcs/class/System.Windows.Forms/System.Windows.Forms/WebBrowser.cs:304
at System.Windows.Forms.WebBrowser.set_Url (System.Uri value) [0x00007] in /run/build/mono/mcs/class/System.Windows.Forms/System.Windows.Forms/WebBrowser.cs:231
at (wrapper remoting-invoke-with-check) System.Windows.Forms.WebBrowser:set_Url (System.Uri)
at Aamanss.MainClass.PrintHelpPage() [0x00024] in /root/Projects/Aamanss/Aamanss/Program.cs:19
at Aamanss.MainClass.Main (System.String[] args) [0x00001] in /root/Projects/Aamanss/Aamanss/Program.cs:34
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
at System.Windows.Forms.WebBrowser.Navigate (System.Uri url) [0x0000e] in /run/build/mono/mcs/class/System.Windows.Forms/System.Windows.Forms/WebBrowser.cs:304
at System.Windows.Forms.WebBrowser.set_Url (System.Uri value) [0x00007] in /run/build/mono/mcs/class/System.Windows.Forms/System.Windows.Forms/WebBrowser.cs:231
at (wrapper remoting-invoke-with-check) System.Windows.Forms.WebBrowser:set_Url (System.Uri)
at Aamanss.MainClass.PrintHelpPage() [0x00024] in /root/Projects/Aamanss/Aamanss/Program.cs:19
at Aamanss.MainClass.Main (System.String[] args) [0x00001] in /root/Projects/Aamanss/Aamanss/Program.cs:34
私はあなたが一般的でWebBrowserナビゲーション作業を行うため、私は心からあなたの1はダミーのためにこれを説明することを願っ方法を見つけ出すことは本当に必死です。 OK
は、コンソールまたは物理プリンタに印刷するために印刷していますか。 – Digvijay
私はコンソールに印刷しています。私はコンソールアプリケーションとしてmonoDevelopでそれを実行しています – Nulle
この回答を確認してください:http://stackoverflow.com/questions/19734151/print-webbrowser-without-previewing-ie-single-click-print – Zsmaster