-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MouseEnter and MouseLeave events of ChromiumWebBrowser control do not fire #1098
Comments
The underlying CEF library captures all mouse events and does not bubble them up to WinForms. There's no way around this for WinForms - if you want to handle mouse events you need to do so in JavaScript. Your alternative is to use the |
Ah interesting thank you very much. Is the general recommendation to use the WPF control? We're "porting" an existing application that is built on winforms which is why I started with the winforms control but it is possible for us to move to WPF if needed (although a bit painful). |
You may be able to hook the underlying handle and capture the raw messages, e.g. |
@amaitland Thank you for the tip. I did try out listening for WM_MOUSELEAVE and WM_MOUSEMOVE but they didn't work well if the mouse was moving fast over the control (missed messages basically). For my use case where I was changing the opacity of the form on mouse hover (in the CSS sense) this resulted in issues where the state would become mixed up (hover when it wasn't hovered or vice versa). I've resorted to using a timer which checks the mouse position to see if it's contained within the bounds of the form. Kind of makes me cringe but it works well haha. |
What handle did you hook? It would likely need to be one of the child handles of the browser control it's self (one of the underlying handles for the Are you actually interested in |
@amaitland I'm pretty sure we aren't looking for focus. The actual use case here is to change the opacity of the form when the user's mouse is hovered over it. (transparent when there is no mouse hover and opaque when there is a mouse hover). (I'm using hover here in the css sense, not the winform sense) I'll take a look at the handles for the browser control itself and report back. Thanks! |
@sarus Not sure if it helps but inspired by you and @amaitland I decided to try intercepting the mouse events to fix another problem I had. This is how I look for the Let me know if you have a cleaner approach than using |
Nice one @jankurianski! An excellent reference 👍 |
@jankurianski Yes agree with amaitland. This is fantastic. Thank you for posting this Gist. Will try to find time in the next week to test it out. Have you noticed missing mouse events when using this approach? As a test I hooked into the mouse events for the form itself to listen for There was also this stackoverflow post basically outlining the same problem and hence the timer based solution: http://stackoverflow.com/questions/12552809/mousehover-and-mouseleave-events-controlling |
@sarus Changing the class ChromeWidgetMessageInterceptor : NativeWindow
{
public ChromeWidgetMessageInterceptor(IntPtr chromeWidgetHostHandle)
{
AssignHandle(chromeWidgetHostHandle);
}
const int WM_MOUSEMOVE = 0x0200;
const int WM_MOUSELEAVE = 0x02A3;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg) {
case WM_MOUSEMOVE:
Console.WriteLine("WM_MOUSEMOVE");
break;
case WM_MOUSELEAVE:
Console.WriteLine("WM_MOUSELEAVE");
break;
}
}
} |
I've added this is |
I don't think so. Other than maybe adding a comment to one of the example projects pointing at the gist and this issue maybe? |
But |
Having the same problem. Also not working for |
Hello,
Not sure if I should be expecting this to work but the MouseLeave and MouseEnter events don't seem to work when using the ChromiumWebBrowser control for WinForms. Here's the code I was using. Should I be expecting these events to trigger properly on the browser control? Thank you!
I'm using the latest CefSharp available from Nuget (41.0.0)
The text was updated successfully, but these errors were encountered: