111,098
社区成员




public partial class FrmTest : Form
{
// 界面上有一个WebBrowser 和 4个Button
private string strUrl = "http://www.cnblogs.com/08shiyan";
public FrmTest()
{
InitializeComponent();
}
/// <summary>
/// 编辑模式
/// </summary>
public void EditMode()
{
if (this.webBrowser1.Document != null)
{
mshtml.IHTMLDocument2 doc = this.webBrowser1.Document.DomDocument as mshtml.IHTMLDocument2;
doc.designMode = "on";
}
}
/// <summary>
/// 启用浏览模式
/// </summary>
public void BrowseMode()
{
if (this.webBrowser1.Document != null)
{
mshtml.IHTMLDocument2 doc = this.webBrowser1.Document.DomDocument as mshtml.IHTMLDocument2;
doc.designMode = "off";
}
}
// 请确保该按钮是应用程序启动后第一次被点击
private void button1_Click(object sender, EventArgs e)
{
this.webBrowser1.DocumentText = string.Empty;
this.webBrowser1.Document.Write(string.Format("<BODY>{0}我的誓言博客2</BODY>", this.strUrl));
this.EditMode();
this.webBrowser1.Document.OpenNew(true);
this.webBrowser1.Document.Write(string.Format("<BODY>{0}我的誓言博客2</BODY>", this.strUrl));
// 注意此时Ctrl + Z 撤销操作将会失效
}
// 请确保该按钮是应用程序启动后第一次被点击
private void button2_Click(object sender, EventArgs e)
{
this.webBrowser1.DocumentText = string.Empty;
this.webBrowser1.Document.Write(string.Format("<BODY>{0}我的誓言博客2</BODY>", this.strUrl));
this.EditMode();
this.webBrowser1.Document.OpenNew(true);
this.webBrowser1.Document.Write(string.Format("<BODY>{0}我的誓言博客2</BODY>", this.strUrl));
this.EditMode(); // 与button1的差别是再次启用编辑模式 // 注意此时Ctrl + Z 撤销操作也会失效
}
// 请确保该按钮是应用程序启动后第一次被点击
private void button3_Click(object sender, EventArgs e)
{
this.webBrowser1.DocumentText = string.Empty;
this.webBrowser1.Document.Write(string.Format("<BODY>{0}我的誓言博客2</BODY>", this.strUrl));
this.EditMode();
this.webBrowser1.Document.OpenNew(true);
this.webBrowser1.Document.Write(string.Format("<BODY>{0}我的誓言博客2</BODY>", this.strUrl));
this.BrowseMode(); // 与button2 的区别是 先关闭编辑模式,再启用编辑模式
this.EditMode();
// 此时 Ctrl + Z 可以使用 ,但此时this.webBrowser1.Document.Body 为null了,杯具中、还是不能解决,问题似乎陷入死循环了。
}
// 重启应用程序
private void button4_Click(object sender, EventArgs e)
{
Application.Restart();
}
}