以前的都是分别在每个EDIT框的OnKeyPress里面写代码:
if key = #13 then
  edit2.setfocus;可不可以在Form的OnKeyPress里写代码.
if key = #13 then
  setNextFocus; 类似于这样的方法来实现?因为在每个EDIT框都写代码太麻烦了.

解决方案 »

  1.   

    orm的Keypreview 设为True
    再在Form的Onkeypress事件中写
    if (key=#13) then
    begin
         key=#0;
         perform(WM_NEXTDLGCTL,0,0);
    end;
      

  2.   

    还可以用这个
    procedure SelectNext(CurControl: TWinControl; GoForward, CheckTabStop: Boolean);procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
    begin
       if (key=#13) then
    begin
         key:=#0;
         SelectNext(ActiveControl, True, True);
    end;
    end;
    GoForward, true:向前找,false:向后找
    CheckTabStop:true 如果Edit 的tabstop为false,则不会选择它,直接跳到下一个.
                false  不考虑tabstop