给你一个采用消息的实例吧:
procedure TfrmMain.EnterToTab(var Msg: TMsg; var Handled: Boolean);
begin
//2005.10.07 20:03由于空格键在按钮上无响应,改为
if(Msg.Message=WM_KEYDOWN)and(Msg.wParam=VK_RETURN) then
if (Screen.ActiveControl is TButton) then//不能是按钮
begin
if Msg.wParam=VK_SPACE then
begin
Keybd_Event(VK_RETURN, 0, 0, 0);
Handled:=True;
end;
end else if not(Screen.ActiveControl is TButtonControl) then//不能是按钮
begin
if Screen.ActiveControl is TDBGrid then
if TDBGrid(Screen.ActiveControl).SelectedIndex=TDBGrid(Screen.ActiveControl).Columns.Count-1 then
TDBGrid(Screen.ActiveControl).SelectedIndex:=0//如果是网格的最后一列,就回到第一列,否则就到下一列
else
TDBGrid(Screen.ActiveControl).SelectedIndex:=TDBGrid(Screen.ActiveControl).SelectedIndex+1
else Keybd_Event(VK_TAB, 0, 0, 0);//如果不是网格,就发送Tab消息
Handled:=True;//表示该消息已经处理。
end;
end;
在主窗体的创建事件中指定:
Alication.OnMessage:=EnterToTab;