使用 WebBrowser 控件作为编辑器时出现问题
我目前正在开发一个项目,其中使用 WebBrowser 控件作为编辑器。我打开了设计模式,它似乎正在工作。我遇到的问题是,当我尝试保存文档并加载另一个文档时,它会弹出“此文档已被修改”。信息。我想做的就是这么简单,
if (frontPage)
{
frontPage = false;
frontContent = webEditor.DocumentText;
webEditor.DocumentText = backContent;
}
else
{
frontPage = true;
backContent = webEditor.DocumentText;
webEditor.DocumentText = frontContent;
}
就像我说的那样,每次我输入一些文本并运行此代码时,它都会弹出一条消息,说它已被修改,并询问我是否要保存。我该如何解决这个问题?
I am currently working on a project where I am using a WebBrowser control as an editor. I have design mode turned on and it seems to be working. The issue im having is when I try to save the Document and load another it pops up the "This document has been modified." message. What I am trying to do is as simple as this
if (frontPage)
{
frontPage = false;
frontContent = webEditor.DocumentText;
webEditor.DocumentText = backContent;
}
else
{
frontPage = true;
backContent = webEditor.DocumentText;
webEditor.DocumentText = frontContent;
}
Like I said everytime I enter some text and run this code it just pops up a message saying its been modified and asks if I want to save. How can I get around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您应该创建以下函数:
每次更改 DocumentText 之前都应该调用它。
You should create the following function:
It should be called every time before you change DocumentText.
你可以
这样设置:
Worked for me 。
You could set
Like this:
Worked for me .
您应该创建以下函数:
每次更改
DocumentText
之前都应该调用它。You should create the following function:
It should be called every time before you change
DocumentText
.更好的解决方案是在实际分配 html 代码之前写入空字符串:
WebBrowser1.Document.Write(string.Empty);
WebBrowser1.DocumentText = "您的代码";
better solution is to write empty string before you actually assign your html code:
WebBrowser1.Document.Write(string.Empty);
WebBrowser1.DocumentText = "your code";
我已经解决了这个问题:
这是来自这个链接:
http:// /social.msdn.microsoft.com/Forums/vstudio/en-US/3a9c1965-8559-4972-95e1-da0e86cf87bb/webbrowser-strange-problem
I have solved this problem so:
This is from this link:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/3a9c1965-8559-4972-95e1-da0e86cf87bb/webbrowser-strange-problem
Windows 窗体加载文档流(由 DocumentText 属性使用)的方式是导航到 about:blank,这将触发文档修改消息,然后在其 DocumentComplete 事件处理程序中加载该流。
由于您已经有一个文档,因此您可以跳过导航并直接通过其 IPersistStreamInit 接口将流加载到现有文档中,就像 Windows 窗体在其 DocumentComplete 事件处理程序中所做的那样。
The way Windows Forms load a document stream (used by the DocumentText property) is to navigate away to about:blank, which triggers the document modified message, then load the stream in its DocumentComplete event handler.
Since you already have a document, you can skip the navigation and load the stream into the existing document directly via its IPersistStreamInit interface like Windows Forms does in its DocumentComplete event handler.
试试这个
webEditor.ScriptErrorsSuppressed = true;
确保您已在 IE 中禁用脚本调试(如果您已打开它)。
Try this
webEditor.ScriptErrorsSuppressed = true;
Make sure you have disabled Script Debugging in IE in case you've turned it on.