Frage

I'm setting WebBrowserShortcutsEnabled to false in order to disable typical Internet Explorer shortcuts in my System.Windows.Forms.WebBrowser implementation. This works fine until I also implement IOLEClientSite and call SetClientSite using the following code:

IOLEObject o = (IOLEObject)this.ActiveXInstance;
o.SetClientSite(this);

If I remove this code, it works and shortcuts are properly disabled. What's going on here?

War es hilfreich?

Lösung

WebBrowser is an ActiveX control. It negotiates with its host to deal with UI implementation details like shortcut keystrokes. It needs to tell the host about it first since the host may want to use the shortcut for its own use.

The normal host is implemented by the internal WebBrowserSite class, derived from WebBrowserSiteBase. You replaced it, now it is your job to implement that negotiation. This is done by IDocHostUIHandler::TranslateAccelerator(), simply return S_OK from your implementation of this method. Which tells the browser that it should not process the keystroke itself.

Andere Tipps

When you override the base functionality of WebBrowser OLE site object, you're at risk of breaking some existing features. You should consult with .NET reference source code for the WebBrowser implementation details which might be affected by your custom site.

Ideally, you should be calling the base site implementation when you override any COM interfaces, which might be tricky, because the most of COM interfaces implemented by .NET are declared as internal.

I dealt with a similar problem here and here.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top