if key=vkReturn then selectText(activewincontrol,false,false);
procedure TForm1.ApplicationEvents1ShortCut(var Msg: TWMKey; var Handled: Boolean); begin if (Msg.CharCode=13) and (Msg.KeyData=18612225) then begin FindNextControl(ActiveControl,True,True,True).SetFocus; Handled:=True; end; end;
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls, DBCtrls;type TForm1 = class(TForm) ADOConnection1: TADOConnection; DataSource1: TDataSource; DBGrid1: TDBGrid; ADOQuery1: TADOQuery; procedure DBGrid1KeyPress(Sender: TObject; var Key: Char); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char); begin if Key = #13 then { 如果不是Enter键 } if not (ActiveControl is TDBGrid) then { TDBGrid不为活动控件 } begin Key := #0; { 忽略Enter键 } Perform(WM_NEXTDLGCTL, 0, 0); { 到下一控件 } end else if (ActiveControl is TDBGrid) then { 判断是否TDBGrid为活动控件 } with TDBGrid(ActiveControl) do if selectedindex < (fieldcount - 1) then { increment the field } selectedindex := selectedindex +1 else selectedindex := 0; end;end.
selectText(activewincontrol,false,false);
var Handled: Boolean);
begin
if (Msg.CharCode=13) and (Msg.KeyData=18612225) then
begin
FindNextControl(ActiveControl,True,True,True).SetFocus;
Handled:=True;
end;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls, DBCtrls;type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ADOQuery1: TADOQuery;
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then { 如果不是Enter键 }
if not (ActiveControl is TDBGrid) then { TDBGrid不为活动控件 }
begin
Key := #0; { 忽略Enter键 }
Perform(WM_NEXTDLGCTL, 0, 0); { 到下一控件 }
end
else
if (ActiveControl is TDBGrid) then { 判断是否TDBGrid为活动控件 }
with TDBGrid(ActiveControl) do
if selectedindex < (fieldcount - 1) then { increment the field }
selectedindex := selectedindex +1
else
selectedindex := 0;
end;end.