I'm using VS 2005 and I'd really like to use the System.Windows.Forms.WebBrowser control. The problem is that I'm having some focus issues it would appear when using a Java applet in the web page that is loaded in the control.
When using the Sun Java Virtual Machine, right clicking on the applet will cause the applet to no longer receive keyboard input. But if I use the MS Java Virtual Machine, then this does not occur. But if I use the Internet Explorer application (not the embedded IE) with Sun Java, the problem does not occur. Also if I used the COM version of the control in VS 2005 instead of System.Windows.Forms.WebBrowser and Sun Java, the problem will still not occur.
So my only conclusion is that there is a problem somewhere in the implementation of the System.Windows.Forms.WebBrowser control. I really would rather use System.Windows.Forms.WebBrowser because of some of its features. Implementing the ability to disable the context menu for instance is quite a bit more difficult if I use the COM version (AxWebBrowser). So I was hoping there was a way to fix this by making a new control that inherits from System.Windows.Forms.WebBrowser and then overrides some method or something.
I have made some progress on that already. After looking at the code for System.Windows.Forms.WebBrowser (with .NET Reflector), I was able to fix the problem half-way. What I mean is, I overrode WndProc and called the default WndProc instead of the WndProc of System.Windows.Forms.WebBrowser when the WM_MOUSEACTIVATE message was received. I was able to right click on the applet and focus was not lost using Sun Java.
However, there is still one remaining problem. Whenever I minimize the main form that the web browser control is on and then bring it back up, right clicking on the applet fails to give it keyboard focus. (Left clicking does bring focus back to the applet.) This also occurs if I bring up another window in front of my app window and click on my app window again. So basically, when my app window loses focus and regains it, I'm unable to give the applet focus by right clicking it. Once again this is something that does not occur in AxWebBrowser (COM).
So that is my problem. Does anyone have any suggestions as to what I might be able to do next? I have attached a project that demonstrates the problem. Just compile and run the app. Make sure you have Sun Java installed as the web page that the app goes to specifically asks for Sun in this case. (There's another page that just uses whatever your default JVM happens to be, but that's beside the point.) When the applet is finished loading, click on the button that says "Existing User" and this is where you can easily see the keyboard focus issues. There's no need to actually login to see the problem in action.
draw.io Desktop 30.2.4 by Razvan Serea
draw.io desktop is a downloadable security-first diagramming application that runs on Windows, MacOS and Linux. Creating diagrams in the desktop app doesn’t need an internet connection. This is useful when you are disconnected or when you must create diagrams in a highly secure environment, where data protection is of the utmost importance. When you use the draw.io desktop app, your diagrams will be stored on your local device. Because this is a stand-alone application, also designed to run offline, there are no interfaces to cloud storage platforms available. Of course, you can still store your diagrams in folders that are synchronised to your cloud storage if you wish.
Easy-to-use diagram editor
The draw.io apps work just like the office and drawing tools you are used to using.
Drag and drop shapes from the shape libraries and drag to draw connectors between them.
Drag connectors to add waypoints and set a precise shape and position, or let them reroute automatically.
Double click and start typing to add a label to anything.
Create tables and swimlane flows with a familiar tool.
Style shapes and connectors with customisable palettes, sketch options, fonts and text formatting tools.
Search for shapes, including in open-source icon libraries.
Use our vast libraries of shapes and templates, organised into logical categories, to create a range of diagrams and infographics.
Generate diagrams from text descriptions using our smart templates.
Diagram faster with keyboard shortcuts.
draw.io Desktop 30.2.4 changelog:
Uses electron 42.4.1
Updates to draw.io core 30.2.4.
Download: draw.io 64-bit | Standalone ~100.0 MB (Open Source)
Download: draw.io 32-bit | ARM64 | ARM64 Standalone
Links: draw.io Home Page | Project page @GitHub | Screenshot
Get alerted to all of our Software updates on Twitter at @NeowinSoftware
Question
Protonic86
I'm using VS 2005 and I'd really like to use the System.Windows.Forms.WebBrowser control. The problem is that I'm having some focus issues it would appear when using a Java applet in the web page that is loaded in the control.
When using the Sun Java Virtual Machine, right clicking on the applet will cause the applet to no longer receive keyboard input. But if I use the MS Java Virtual Machine, then this does not occur. But if I use the Internet Explorer application (not the embedded IE) with Sun Java, the problem does not occur. Also if I used the COM version of the control in VS 2005 instead of System.Windows.Forms.WebBrowser and Sun Java, the problem will still not occur.
So my only conclusion is that there is a problem somewhere in the implementation of the System.Windows.Forms.WebBrowser control. I really would rather use System.Windows.Forms.WebBrowser because of some of its features. Implementing the ability to disable the context menu for instance is quite a bit more difficult if I use the COM version (AxWebBrowser). So I was hoping there was a way to fix this by making a new control that inherits from System.Windows.Forms.WebBrowser and then overrides some method or something.
I have made some progress on that already. After looking at the code for System.Windows.Forms.WebBrowser (with .NET Reflector), I was able to fix the problem half-way. What I mean is, I overrode WndProc and called the default WndProc instead of the WndProc of System.Windows.Forms.WebBrowser when the WM_MOUSEACTIVATE message was received. I was able to right click on the applet and focus was not lost using Sun Java.
However, there is still one remaining problem. Whenever I minimize the main form that the web browser control is on and then bring it back up, right clicking on the applet fails to give it keyboard focus. (Left clicking does bring focus back to the applet.) This also occurs if I bring up another window in front of my app window and click on my app window again. So basically, when my app window loses focus and regains it, I'm unable to give the applet focus by right clicking it. Once again this is something that does not occur in AxWebBrowser (COM).
So that is my problem. Does anyone have any suggestions as to what I might be able to do next? I have attached a project that demonstrates the problem. Just compile and run the app. Make sure you have Sun Java installed as the web page that the app goes to specifically asks for Sun in this case. (There's another page that just uses whatever your default JVM happens to be, but that's beside the point.) When the applet is finished loading, click on the button that says "Existing User" and this is where you can easily see the keyboard focus issues. There's no need to actually login to see the problem in action.
Thanks in advance.
WindowsApplication2.zip
Link to comment
https://www.neowin.net/forum/topic/431254-c-net-20-webbrowser-control-focus-issues/Share on other sites
4 answers to this question
Recommended Posts