[.NET 2.0] WebBrowser Control Focus Issues

Damaged Soul

Newcomer
Joined
Feb 8, 2006
Messages
1
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. 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.
 

Attachments

Back
Top