I am trying to load an html document into a WebBrowser control, but I am on my way. Here's a sample:
public void Button_Click(object sender, EventArgs e) { webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_c); webBrowser1.DocumentText = "<html>foo</html>";
The wb_c event handler is also not called. A web browser control is defined as a form control. The form itself consists only of a browser and a button.
Does anyone have any ideas? I used to use this class without any problems, but this time .Net gods deny me! My ultimate goal is to print the document, but right now I can't even accept it to accept my HTML. Maybe I need holy water or something like that.
Edit: if the title bar is deleted above, the wb_c event handler never fires. It's like something is wrong with the COM component itself, or something like that.
Edit 2: by popular request, here is the full code of my code.
public partial class Form2 : Form { [STAThread] public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form2()); } public Form2() { InitializeComponent(); webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_c); } void wb_c(object sender, WebBrowserDocumentCompletedEventArgs e) { throw new Exception("The method or operation is not implemented."); } private void button1_Click(object sender, EventArgs e) { webBrowser1.DocumentText = "<html>foo</html>"; } } partial class Form2 {
This is a .Net 2.0 project, launched in VS 2005. System.Windows.Forms.dll is v2.0.50727.
EDIT 3: Adding this line to the end of the Form2 constructor:
webBrowser1.Navigate("about:blank");
It starts the event handler, but it does not affect the behavior of the code when setting the text of the document. Setting a breakpoint after the line webBrowser1.Document.Text still gives the same line "\ 0", and trying to set the header still gives COM HERROR.