I found a solution after a little trial and error.
The code below is the event handler for a tab control that tabs back and forth between a WYSIWYG Html editor and the HTML source:
PHP Code:
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { string html = "<HTML><HEAD><TITLE></TITLE></HEAD><BODY></BODY></HTML>"; switch (tabControl1.SelectedIndex) { case 0: // Coming from Source tab MSHTML.IHTMLDocument2 doc2 = (MSHTML.IHTMLDocument2)document; doc2.open("about:blank", EMPTY_PARAMETER, EMPTY_PARAMETER, EMPTY_PARAMETER); doc2.expando = true; if (this.txtHtmlSource.Text != string.Empty) { html = this.txtHtmlSource.Text; } doc2.write(html); doc2.close(); break; case 1: // Coming from Design tab MSHTML.IHTMLDocument3 doc3 = (MSHTML.IHTMLDocument3)document; if (doc3.documentElement != null) { html = doc3.documentElement.outerHTML; } html = html.Replace(" contentEditable=true", ""); //MSHTML enters this this.txtHtmlSource.Text = html; break; } }
Basically, to set the full html I had to open a blank html document and then use the IHTMLDocument2 interface to write to its document.
On the reverse (getting the HTML), I used the IHTMLDocument3 interface.
__________________
online-etraining - free online training in Java, J2EE, and MySQL.
rickysays - answers and advice from a geek who knows stuff.
|