需要用回车键代替TAB键下移一个控件时,把KeyPress设为True,加入下列代码拦截击键:
Procedure TForm1.FormKeyPress(Sender:Tobject;Var Key:Char);
Begin
if key = #13 then {判断是按执行键}
if not (ActiveControl is TDbgrid) then
begin {不是在TDbgrid控件内}
key := #0;
perform(WM_NEXTDLGCTL, 0, 0); {移动到下一个控件}
//或
PostMessage(Activecontrol.Handle, WM_KEYDOWN, VK_TAB, 0); //以TAB代替回车
//或
SelectNext(ActiveControl as TWinControl, True, True);
end
else
if (ActiveControl is TDbgrid) then {是在 TDbgrid控件内}
begin
with TDbgrid(ActiveControl) do
if Selectedindex < (FieldCount - 1) then
Selectedindex := Selectedindex + 1 //移动到下一字段
else Selectedindex := 0;
end;
End;