这里有很多类似的问题,但我找不到我的问题的答案。
I have a TRichEdit
and want to implement some custom behaviour when the user presses Tab. I set the rich edit's WantTabs
property to True
and tried to add my custom behaviour in OnKeyDown
, which works fine, but unfortunately after that the "normal" tab behaviour is executed as well (inserting a tab character in the edit). I tried setting Key
to 0
in the event handler but that doesn't help.
如何防止执行“正常”选项卡行为?
Use the OnKeyPress
事件代替:
procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = chr(VK_TAB) then
begin
beep;
Key := #0;
end;
end;
或者,如果您确实需要使用OnKeyDown
事件,只需删除关键消息:
procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
msg: TMsg;
begin
if Key = VK_TAB then
begin
beep;
while PeekMessage(msg, RichEdit1.Handle, WM_KEYFIRST, WM_KEYLAST,
PM_REMOVE) do;
end;
end;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)