在填写信息时要能用回车键或箭头来控制,怎样实现,请各位朋友帮忙。其中FORM中有TEdit,TButton,TLable,TDateTimePicker,TUpDown,TComboBox,TRadioGroup,TComboBox......能不能编一段针对所有FORM通用的代码,谢谢大家!

解决方案 »

  1.   

    设置窗体KeyPreview为true
    在窗体FormKeyPress(Sender: TObject; var Key: Char)事件中加入下面代码
      if Key = Chr(13) then Keybd_Event(VK_TAB, MapVirtualKey(VK_TAB, 0), 0, 0);
      

  2.   

    我这里有在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;