MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
423 stars 51 forks source link

WinForms MenuStrip doesn't deactivate and close when clicking inside a web view #3288

Open ow-- opened 1 year ago

ow-- commented 1 year ago

Description The WinForms MenuStrip doesn't deactivate and close when clicking inside a web view. This could be reproduced in the WinForms sample app while the WPF and Win32 sample apps works as expected.

Version SDK: 1.0.1587.40 Runtime: Release 110.0.1587.63 Framework: WinForms OS: Win11

Repro Steps In the WinForms sample app (WebView2WindowsFormsBrowser):

Expected: Web view gets focus and menu deactivates and closes. Actual: Web view seems to get focus fine but the menu never deactivates and stays open.

Screenshots winforms-menu

Additional context Under hit transparent mode (--enable-features=msWebView2BrowserHitTransparent) this does work fine but it's not really an option for us since we need to be able to handle key events in the hosted web app before they reach the host.

I couldn't really tell if this is related or similar to #397 or any of the ones mentioned within.

ForeverInfinity commented 1 year ago

I also had the same trouble.

0x526f6d656f commented 1 year ago

Got the same issue.

xu-ms commented 1 year ago

@ForeverInfinity @0x526f6d656f If you only expected webview gets focus and menu deactivates and closes, you can add BrowserArgument --enable-features=msWebView2BrowserHitTransparent when create the webview.

@ow-- Based on the information provided, it is possible that the behavior you are experiencing could be attributed to a design flaw in the control. In order to provide you with a more accurate explanation, we will conduct further investigation and get back to you with our findings as soon as possible.

ForeverInfinity commented 1 year ago

@ForeverInfinity @0x526f6d656f If you only expected webview gets focus and menu deactivates and closes, you can add BrowserArgument --enable-features=msWebView2BrowserHitTransparent when create the webview.

@ow-- Based on the information provided, it is possible that the behavior you are experiencing could be attributed to a design flaw in the control. In order to provide you with a more accurate explanation, we will conduct further investigation and get back to you with our findings as soon as possible.

Works fine. Thanks for answering

0x526f6d656f commented 1 year ago

@ForeverInfinity @0x526f6d656f If you only expected webview gets focus and menu deactivates and closes, you can add BrowserArgument --enable-features=msWebView2BrowserHitTransparent when create the webview.

@ow-- Based on the information provided, it is possible that the behavior you are experiencing could be attributed to a design flaw in the control. In order to provide you with a more accurate explanation, we will conduct further investigation and get back to you with our findings as soon as possible.

In our case we also need to handle key events from the web app, so it's not an option for us I'm afraid.

0x526f6d656f commented 12 months ago

@xu-ms Any update on this?

wintal commented 3 months ago

We've run into this problem as well. Menu's don't close, and keyboard buttons pressed to manipulate the menus (Esc, arrow keys, alt, etc) don't work. If we use --enable-features=msWebView2BrowserHitTransparent then the keys work for the menus but not for the hosted content (can't use arrow keys to select from lists or move in textboxes etc).

fotodmitriru commented 3 months ago

And we've also faced this problem.

fotodmitriru commented 3 months ago

Is it possible to create an interface like IKeyboardHandler? And called him before a keyboard event is sent to the renderer. Method bool OnPreKeyEvent. Return true, if method process key events.

Jeroen3000 commented 1 week ago

I am struggling with the same problem; menu (MenuStrip class in Winforms) does not get deactivated/closed when the webwiew2 receives the focus. "--enable-features=msWebView2BrowserHitTransparent" is not a solution, this disables the arrow keys in the html controls (textbox, etc..) in the webview2 control. Looks like the problem is that the menu control does not get notified by the webview2 control of receiving the focus. Any news when this will get fixed?