设置窗体KeyPreview为true 在窗体FormKeyPress(Sender: TObject; var Key: Char)事件中加入下面代码 if Key = Chr(13) then Keybd_Event(VK_TAB, MapVirtualKey(VK_TAB, 0), 0, 0);
我这里有在grid中用回车键代替tab键的例子 procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then if ActiveControl = DBGrid1 then begin TDBGrid(ActiveControl).SelectedIndex := TDBGrid(ActiveControl).SelectedIndex + 1; Key := #0; end; end;
在窗体FormKeyPress(Sender: TObject; var Key: Char)事件中加入下面代码
if Key = Chr(13) then Keybd_Event(VK_TAB, MapVirtualKey(VK_TAB, 0), 0, 0);
procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
if ActiveControl = DBGrid1 then
begin
TDBGrid(ActiveControl).SelectedIndex := TDBGrid(ActiveControl).SelectedIndex + 1;
Key := #0;
end;
end;