0

I need to show Winforms ContextMenuStrip but ChromiumWebBrowser gets in the way. By getting in the way I mean the ContextMenuStrip loses some of its significant behavior like the ability to process mouse and keyboard messages and auto closing when losing focus because all input events are consumed by the embedded browser. A question similar to this was asked 6 years ago but someone told me I have to ask my own question. So, here is my question: How can I show my own contextmenustrip without the browser interfering with it? I hope someone have already found a solution or even a workaround to this. Or perhaps a way to tell the webrowser that the form hosting it have some other business to do that his intervention is irrelevant.

P. S. My cefsharp library is still version 83.4.20.0.

Abet
  • 123
  • 1
  • 5
  • Not tested, but you can try with this https://stackoverflow.com/a/46290428/18452174 to avoid show the browser context menu and try to show your contextmenu. You also can try to do the same implementing OnBeforeContextMenu of IContextMenuHandler interface of browser. If this don't works, you can add also a IKeyboardHandler in which you manage the keys when your context menu is visible. – Victor Jun 02 '22 at 09:22
  • Integrating CEF into your apps existing message loop is one option see https://github.com/cefsharp/CefSharp/wiki/General-Usage#multithreadedmessageloop – amaitland Jun 02 '22 at 20:50

1 Answers1

0

I guess I've found a workaround from the similar question I was talking about: Show Winforms Contextmenu over ChromiumWebBrowser. I just made a simple refinement of the workaround he have suggested which he revamped later. The workaround is still to disable the webbrowser window handle when a menu is about to open and enable it back when the menu is about to close.

Take note that I put emphasis to the window handle here because I am not talking about the handle of the chromiumwebbrowser control but the handle retured by IBrowser interface. I perused the webbrowser window handles and there are four window handles involved: 1. the webbrowsers' usercontrol handle; 2. the CefBrowserWindow handle (CefBrowserWindow is the window's class name)—child of the former; 3. the Chrome_WidgetWin_0 that displays the web page (child of handle 2); and, 4: the Chrome Legacy Window handle (child of handle 3). It is the third handle that I worked with.

Abet
  • 123
  • 1
  • 5