-->

How to make TWebBrowser ignore accelerator chars o

2020-07-21 04:56发布

问题:

I have a TWebBrowser placed on a form with the designMode enabled.
Bellow the browser I have a close button with the Caption set to 'Clos&e'.
When I am editing the contents of a document inside the WebBrowser and I press the key E the button close is called.
It appears that it is treating TWebBrowser like other controls that don't handle keys and/or don't accept chars (e.g. TButton).

How can I solve this?

Thanks in advance.

回答1:

Descend from TWebBrowser, override the CN_CHAR message handler, and return 0. Triggering the shortcut with Alt+E will still work.

type
  TWebBrowser = class(SHDocVw.TWebBrowser)
    procedure CNChar(var Message: TWMChar); message CN_CHAR;
  end;

...

procedure TWebBrowser.CNChar(var Message: TWMChar);
begin
  Message.Result := 0;
end;