NOTE. This is about the inline behavior of the control, not the creation of 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 many years, but suddenly I noticed that earlier, when I double-clicked, it would automatically select the word that was pressed (it was not my code, it just happened to the control).
Suddenly (not entirely accurate), double-clicking on the text in the control (both in edit mode and in view mode) does nothing. Itβs not easy to troubleshoot because itβs not my code, however, since in the past I depended on this functionality, now it affects my final product.
Any idea that has recently changed (on Windows or .Net) that would affect this (the same version of my application works fine in the old version of Win7, but not in the latest version of Win7)? Also, how can I revert to previous functionality? Do I have to plug in my own double click even in the DOM and then start parsing the text to manually select it (uh!)?
I looked through the entire answer to this question, but basically I just see how to connect to DOM events, nothing about the latest changes that could cause the problem above). Any help would be greatly appreciated.
I use VS 2010, VB, Win7 x64, IE 10.0.6, .Net 3.5 (regardless of the latter) when the problem occurs (compiled, so I doubt that it is VS or VB).
When I run the same code (compiled) on Win7 x86 with IE 8 (simple Win7 Pro with zero updates installed), it works fine.
After some additional testing on the new version of Win7 x86 (where everything was fine), as soon as I installed IE 10 and NOTHING ELSE, the problem starts to arise. So, I'm sure the problem is with IE 10.
Steps to play:
- Create a new VB.Net project in VS 2010 by customizing .Net 3.5
- Create usercontrol <--- this step is the key
- Add web browser to usercontrol
Add this code to 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
Add this control to the form.
Add a button to the form with the next 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
Run the project and click the button
- Then try double-clicking the word "interesting" and notice that it does not select.
If you drop the webbrowser control directly into the form, it will work fine. The problem with usercontrol (and this is only a problem after upgrading 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.