How to make TWebBrowser ignore accelerator chars o

2020-07-21 05:13发布

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条回答
该账号已被封号
2楼-- · 2020-07-21 06:01

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;
查看更多
登录 后发表回答