没有这样的事件,因为 DocumentText 是一个简单的字符串。我会创建一个字符串变量来存储最后保存的文本,并在每个 KeyDown / MouseDown / Navigating 事件中检查它。
string lastSaved;
private void Form_Load(object sender, System.EventArgs e)
{
// Load the form then save WebBrowser text
this.lastSaved = this.webBrowser1.DocumentText;
}
private void webBrowser1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
// Check if it changed
if (this.lastSaved != this.webBrowser1.DocumentText)
{
// TODO: changed, enable save button
this.lastSaved = this.webBrowser1.DocumentText;
}
}
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
// Check if it changed
if (this.lastSaved != this.webBrowser1.DocumentText)
{
// TODO: ask user if he wants to save
// You can set e.Cancel = true to cancel loading the next page
}
}