Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebBrowser control not auto-selecting text on double-click after IE 10 install

NOTE: This is about the control's built-in behavior, not about creating a double-click event.

One of my projects uses the Windows.Forms.WebBrowser control as an editor and viewer for HTML. It has been working fine for years but suddenly I noticed that before when I would double-click it would automatically select the word which was clicked (this was not my code, just happened with the control).

Suddenly (not exactly sure when), double clicking text in the control (both in edit mode or in view mode) does nothing. It's hard to troubleshoot because it is not my code doing it, however, since I depended on this functionality in the past, it is now impacting my final product.

Any idea what would have recently changed (in Windows or in .Net) which would affected this (the same version of my app works fine in older Win7 but not in the most up-to-date Win7)? Also, how can I get the previous functionality back? Must I wire up my own double-click even on the DOM and then start parsing the text to manually select it (uh!)?

I've looked all over for the answer to this question but mostly I just see how to wire up to DOM events, nothing about recent changes which would cause the problem above). Any help would be greatly appreciated.

I'm using VS 2010, VB, Win7 x64, IE 10.0.6, .Net 3.5 (whatever the latest one is) when the problem happens (compiled so I doubt it is VS or VB).

When I run the exact same code (compiled) on Win7 x86 with IE 8 (Win7 Pro plain, with zero-updates installed) it works just fine.

After some further testing, on the Win7 x86 fresh install (where everything was fine) as soon as I install IE 10 and NOTHING ELSE the problem starts to happen. So, I'm pretty sure the problem lies with IE 10.

Steps to reproduce:

  1. Create a new VB.Net project in VS 2010, targetting .Net 3.5
  2. Create a usercontrol <--- this step is the key
  3. Add a webbrowser to the usercontrol
  4. Add this code to the usercontrol

    Public Sub LoadHTML(html As String)
        WebBrowser1.DocumentText = html
    
        Do Until WebBrowser1.ReadyState = WebBrowserReadyState.Complete
            Application.DoEvents()
        Loop
    
        WebBrowser1.Document.Body.SetAttribute("contentEditable", "false")
    End Sub
    
  5. Add that control to a form

  6. Add a button to the form with the following button.Click event:

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        UserControl1.LoadHTML("<html><body>This is a test interesting is it not?</body></html>")
    End Sub
    
  7. Run the project and click the button

  8. Then, try to double-click the word "interesting" and notice it does not select.

If you throw the webbrowser control directly on the form, it will work fine. The problem is with the usercontrol (and it is only a problem after updating to IE10).

I can reproduce the problem using VS 2010 using .Net 3.5 and 4.0. I can reproduce the problem using VS 2012 using .Net 4.5.

like image 392
John Avatar asked Jul 06 '13 04:07

John


1 Answers

The problem is actually a bug in IE 10. This was confirmed by Microsoft here.

The saddest part is that they said they would not be fixing it any time soon (if ever) because it affects too few people (though it does affect thousands of my company's customers).

like image 153
John Avatar answered Nov 15 '22 09:11

John