How cool is this? As a fan of Binary DHTML behaviors, I gotta say that the new Web Browser control for WinForms in Visual Studio 2005 looks pretty slick so far! Below I have a code snippet that I'm using to build a control dynamically, attach (and detach) an event, and then control the HTML document within...
HtmlElement
button = null;
private
void Form1_Load(object
sender, EventArgs e) {
this.webBrowser1.Navigate("about:blank");
this.webBrowser1.DocumentCompleted +=
new
WebBrowserDocumentCompletedEventHandler(webBrowser1_Initialize);
}
private
void webBrowser1_Initialize(object
sender, WebBrowserDocumentCompletedEventArgs
e) {
this.webBrowser1.DocumentCompleted -=
this.webBrowser1_Initialize;
this.webBrowser1.Document.Body.InnerHtml =
"<h1>Hello World!</h1>";
button =
this.webBrowser1.Document.CreateElement("input");
button.SetAttribute("type",
"button");
button.SetAttribute("value",
"GoTo Google");
this.webBrowser1.Document.Body.AppendChild(button);
button.Click
+=new
HtmlElementEventHandler(button_Click);
}
private
void button_Click(object
sender, EventArgs e) {
this.webBrowser1.Navigate("http://www.google.com");
}