小弟使用WebBrowser开发HTML编辑器是当为WebBrowser的DocumentText属性赋值后,就无法添加/编辑WebBrowser中的内容了!!
在赋值的时候添加xxx.Document.ExecCommand("ModeSize", false, null);也无法进入编辑模式。

解决方案 »

  1.   

    我的也很奇怪,在xp系统下可以编辑,在win7下就不能编辑了,不知道是什么原因,和楼主一起求高手指点。我的是这么写的:
                  webBrowser1.DocumentText = string.Empty;            webBrowser1.Document.ExecCommand("EditMode", false, null);//设置为编辑状态            webBrowser1.Document.ExecCommand("LiveResize", false, null);
      

  2.   


    /// <summary>
            /// 初始化WebBorwer控件的编辑功能
            /// </summary>
            private void OnInitHtmlEditor()
            {
                if (this.DesignMode == false)
                {
                    this.m_WebBrower.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(m_WebBrower_DocumentCompleted);
                }
               
                this.m_WebBrower.DocumentText = "<html><Body></Body></html>";
                this.doc = this.m_WebBrower.Document.DomDocument as IHTMLDocument2;
                if (!this.m_ReadOnly)
                {
                    // 当该控件进入编辑模式后,文档一旦改变就会弹出保存对话框
                    // 所以在对DocumentText属性赋值后,调用this.m_axHtmlEditor.AxBorwse.Document.OpenNew(true);即可。                
                    this.doc.designMode = "On";                
                }
                this.m_tsForeColor.EditValue = Color.Black;
                // 等待完成初始化,否则Body属性为空
                while(this.m_WebBrower.Document.Body == null)
                {
                    Application.DoEvents();
                }                        if (!this.DesignMode)
                {
                    this.AxHTMLDocument.ExecCommand("FontName", false, this.m_tsFontName.EditValue);
                    this.AxHTMLDocument.ExecCommand("FontSize", false, this.m_tsFontSize.EditValue);
                }
            }
      

  3.   

     
    解决方法,我就这样搞定的
    webBrowser1.Navigate("about:blank");
    webBrowser1.Document.Write(string.Empty);
    webBrowser1.Document.ExecCommand("EditMode", false, null);//设置为编辑状态
    webBrowser1.Document.ExecCommand("LiveResize", false, null);
      

  4.   

    用webBrowser1.Document.Write();
    而不用webBrowser1.DocumentText=value;
      

  5.   

    DocumentText的加载是异步的,要到等加载完触发DocumentComplete的时候才可以改编辑模式。
      

  6.   


    我郁闷了好几天了,终于解决了,真心感谢~~~~哈哈,不用客气,我之前也试过好长时间~ 不过用Document.Wirte()之前,还是先要给Documnet
    赋一个值,要不Document为null会报错了~ 
      

  7.   

    遇到同样的问题啊,XP系统可以,win7下就不行了;
    现在终于解决了,爽歪歪:webBrowser1.Document.Write();
    看来CSDN的牛人还是有时间理我们的