Internet Explorer 9 RC stops my WinForms WebBrowser control to work in editing mode

后端 未结 9 1775
渐次进展
渐次进展 2020-12-09 13:45

Using the IHtmlDocument2.designMode property set to On to switch a WebBrowser control hosted on a Windows Forms form to editing mode suddenly stopp

相关标签:
9条回答
  • 2020-12-09 14:22

    I use HTML Editor Control, I solved this problem adding the DocumentComplete event

    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        (((sender as WebBrowser).Document.DomDocument as IHTMLDocument2).body as HTMLBody).contentEditable = "true"; 
    }
    
    0 讨论(0)
  • 2020-12-09 14:29

    Another Code Project user suggested to use the following code:

    First, add event DocumentCompleted:

    private void SetupEvents()
    {
        webBrowser1.Navigated += webBrowser1_Navigated;
        webBrowser1.GotFocus += webBrowser1_GotFocus;
        webBrowser1.DocumentCompleted += this.theBrowser_DocumentCompleted;
    }
    

    Then write the function:

    private void theBrowser_DocumentCompleted(
        object sender, 
        WebBrowserDocumentCompletedEventArgs e)
    {
        webBrowser1.Document.Write(webBrowser1.DocumentText);
        doc.designMode = "On";
    }
    

    Although I did not test this, I want to document it here for completeness.

    0 讨论(0)
  • It's fixed if the property is set after the document is loaded

    private void DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
    
        IHTMLDocument2 Doc = Document.DomDocument as IHTMLDocument2;
        Doc.designMode = @"On";
    }
    
    0 讨论(0)
  • 2020-12-09 14:38

    I was also able to get this to work using the following inside the DocumentCompleted event:

    IHTMLDocument2 Doc = browserControl.browser.Document.DomDocument as IHTMLDocument2;
    if (Doc != null) Doc.designMode = @"On";
    

    Thanks everyone!

    0 讨论(0)
  • 2020-12-09 14:39

    Just want to add that I am also unable to enter designmode (using a WebBrowser control in my case). This was not an issue in the beta. Definitely new with the RC.

    0 讨论(0)
  • 2020-12-09 14:40

    We just need an empty editable control. I did however step through debugger and add value to the control's InnerHtml and it displayed it fine, and I could edit it.

    Small update, we were able to get the control editable using this line also:

    browserControl.browser.Document.Body.SetAttribute("contentEditable", "true");
    

    This allows us to avoid referencing mshtml, (don't have to include Microsoft.mshtml.dll)

    This lets us avoid increasing our installation size by 8 megs.

    0 讨论(0)
提交回复
热议问题