或者在窗体的ONFormKeyDown事件中写 FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if not (ActiveControl is TDBGrid) then case Key of VK_ESCAPE: Close; VK_RETURN: begin if Shift = [ssShift] then Perform(WM_NEXTDLGCTL, 1, 0) else Perform(WM_NEXTDLGCTL, 0, 0); end; VK_F4, VK_DOWN: if screen.ActiveControl is TCustomEdit then if (Key = VK_F4) or ((Key = VK_DOWN) and (Shift = [ssAlt])) then TCustomEdit(screen.ActiveControl).Perform(WM_LBUTTONDBLCLK, 0, 0); end;end;
设好窗口中控件的TAB顺序,然后将主窗体的keypreview置为trueprocedure TfmProjectInfo.FormKeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then begin Key := #0; Keybd_event(VK_TAB, 0, 0, 0); end; end;这样的话,在上一个控件中按回车键就会跳到下一个控件
.........
ONKEYPREES事件 是密码输入框的事件
不是登陆按钮的事件
FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if not (ActiveControl is TDBGrid) then
case Key of
VK_ESCAPE: Close;
VK_RETURN:
begin
if Shift = [ssShift] then
Perform(WM_NEXTDLGCTL, 1, 0)
else
Perform(WM_NEXTDLGCTL, 0, 0);
end;
VK_F4, VK_DOWN:
if screen.ActiveControl is TCustomEdit then
if (Key = VK_F4) or ((Key = VK_DOWN) and (Shift = [ssAlt])) then
TCustomEdit(screen.ActiveControl).Perform(WM_LBUTTONDBLCLK, 0, 0);
end;end;
begin
if Key = #13 then
begin
Key := #0;
Keybd_event(VK_TAB, 0, 0, 0);
end;
end;这样的话,在上一个控件中按回车键就会跳到下一个控件