Welcome Guest Search | Active Topics | Sign In | Register

How to cancel the Command event on a WebView Options
Jodel
Posted: Monday, January 25, 2021 5:04:31 PM
Rank: Newbie
Groups: Member

Joined: 2/20/2020
Posts: 9
Hello,

We're using an EO.WebBrowser.WebView in our application (Winforms) and were wondering if there is any way of cancelling the Command event when the WebView doesn't have the focus.

When we switch the focus to any other control, it still catches keyboard events, which makes it impossible for us to handle them elsewhere. It doesn't seem to be handling CancelEventArgs, and I can't find any related property.

Thanks !

eo_support
Posted: Wednesday, January 27, 2021 2:04:39 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

We are not aware of such issue. Can you isolate the problem into a small test project and then send the test project to us? See here for more details:

https://www.essentialobjects.com/forum/test_project.aspx

Thanks!
Jodel
Posted: Wednesday, January 27, 2021 2:42:43 PM
Rank: Newbie
Groups: Member

Joined: 2/20/2020
Posts: 9
I just sent you a small sample to easily reproduce the issue, thanks!
eo_support
Posted: Wednesday, January 27, 2021 3:17:39 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

We have looked into your test project. This behavior is in fact by design.

The Shortcut property works when focus is inside the same parent window of the WebView. This is similar to the fact that when a Button control has a shortcut, pressing that shortcut anywhere in the form would trigger the button's click command. This occurs as long as the focus is inside the same window that contains the button. In fact this is the primary purpose of the shortcut --- to trigger command when focus is NOT on the control. The same concept is true for menu item as well.

However if the focus is in a different window, then it will not be triggered.

If you only want the command to be triggered when the focus is in the WebView, there are a few options:

1. The easiest way is probably to check whether the WebView indeed has focus inside your event handler and then skip the intended action if focus is not in the WebView;
2. You can handle the WebView's KeyPress/KeyDown event instead. This way you can catch/trigger keyboard shortcuts based on any logic you would like;
3. You can also use Windows.Forms' built-in shortcut support --- for example, if you use menu, you can have Ctrl+P for printing for a menu item and it will be triggered regardless where the focus is. While this might look like exactly the opposite of what you wanted but really it is how shortcut works. The reason that WebView provides Shortcuts is not to change how shortcut works, but to give you an additional place to define shortcuts;

Hope this helps. Please feel free to let us know if you still have any question.

Thanks!
Jodel
Posted: Wednesday, January 27, 2021 3:42:03 PM
Rank: Newbie
Groups: Member

Joined: 2/20/2020
Posts: 9
Hello,

Just to be sure, is there no way for you to implement a Cancel property on that event ? Option no.1 is basically what we're after, but we can't just skip the action, we have to cancel it in order for another control to receive it. The other 2 options are really not ideal for us.

Thanks
eo_support
Posted: Wednesday, January 27, 2021 3:51:28 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

In that case you should use option #2 instead. This option will give you full control of what to do. It is not possible to support cancelation of Shortcut directly on the WebView control because shortcuts are in fact triggered asynchronously.

Thanks!
Jodel
Posted: Wednesday, January 27, 2021 3:54:04 PM
Rank: Newbie
Groups: Member

Joined: 2/20/2020
Posts: 9
I see, we'll try to figure something out. Thanks for your help!
eo_support
Posted: Wednesday, January 27, 2021 3:55:32 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
You are very welcome. Please feel free to let us know if there is anything else.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.