SGraham1985

i am creating a winform and i want to display several tables in html. I have read up and the webbrowser seems to be the way to do this. I have managed to print out the tables once, however, the second time i try to update the webbrowser it just goes blank. The html in the webbrowser changes on the event of a combo box. I dont understand why it works the first time, but not the second and why are there no errors I would be grateful for any feedback, thankyou, Simon Graham

Code:

private void workoutPrintCombo_SelectedIndexChanged(object sender, EventArgs e)

{

object empty = System.Reflection.Missing.Value;

axWebBrowser1.Navigate("about:blank", ref empty, ref empty, ref empty, ref empty);

mshtml.IHTMLDocument2 doc = axWebBrowser1.Document as mshtml.IHTMLDocument2;

doc.clear();

doc.writeln(createHTMLcode());

doc.close();

}

Note i found this code on

http://ryanfarley.com/blog/archive/2004/12/23/1330.aspx - it is not my own




Re: Windows Forms General WebBrowser control in Winforms

Friendly Dog

First of all, you can try to move the Navigate call outside "SelectedIndexChanged" handler - put it in Form_load or somewhere else. It doesn't need to be called so frequently.

Second, .Net comes with its own WebBrowser control. I recommend you use that. Below is the code I created using a WebBrowser control. Every time when I click on the button the browser gets refreshed with no problem. Note that "OpenNew" call is required, according to MS documentation.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace WebBrowserWithHTML

{

public partial class Form1 : Form

{

int i = 1;

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

HtmlDocument doc = webBrowser1.Document.OpenNew(true);

doc.Write("<HTML><BODY>This is a new HTML document." + i.ToString() + "</BODY></HTML>");

i++;

}

private void Form1_Load(object sender, EventArgs e)

{

webBrowser1.Navigate("about:blank");

}

}

}






Re: Windows Forms General WebBrowser control in Winforms

SGraham1985

Cheers, i couldn't get

HtmlDocument doc = webBrowser1.Document.OpenNew(true);

to work because there was no OpenNew() method in Document, however, by putting

webBrowser1.Navigate("about:blank");

in the load_form part it works fine. Thanks very much for your help! Simon :)