如何使按下Enter(回车)键后使焦点自动跳到窗体上的下一个控件上?其实也就是Enter模仿tab键的功能.我在Form的keyXXXX事件中写代码,但是不起作用.

解决方案 »

  1.   

    要将Form的KeyPreview设为True, 这样传给控件的消息会首先传给窗体Form,只有这样窗体才有机会处理按键消息 
      

  2.   

    如果是用enter鍵來代替tab鍵就用下面的這個函數。
    procedure SetReturn(Sender: TObject; Key: Word);
    begin
      case Key of
        Vk_Return:
          begin
            Sendkeys('{TAB}');
          end;
        Vk_UP:
          begin
            Sendkeys('~{TAB}');
          end;
      end;
    end;
    function SendKeys(S: String): TSendKeyError;
    { This is the one entry point.  Based on the string passed in the S  }
    { parameter, this function creates a list of keyup/keydown messages, }
    { sets a JournalPlayback hook, and replays the keystroke messages.   }
    begin
      Result := sk_None;                     // assume success
      try    if Playing then raise ESKAlreadyPlaying.Create('');
        MessageList := TMessageList.Create;  // create list of messages
        ProcessKey(S);                       // create messages from string
        StartPlayback;                       // set hook and play back messages
      except
        { if an exception occurs, return an error code, and clean up }
        on E:ESendKeyError do begin
          MessageList.Free;
          if E is ESKSetHookError then
            Result := sk_FailSetHook
          else if E is ESKInvalidToken then
            Result := sk_InvalidToken
          else if E is ESKAlreadyPlaying then
            Result := sk_AlreadyPlaying;
        end
        else
          { Catch-all exception handler }
          Result := sk_UnknownError;
      end;
    end;
      

  3.   

    procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if key = vk_return then
        perform(WM_NEXTDLGCTL, 0, 0);
    end;
      

  4.   

    procedure TfrmBorrow_Edt.edtBalanceKeyPress(Sender: TObject;
      var Key: Char);
    begin
      if (key = #13) then
        begin
         Perform(WM_NEXTDLGCTL,0,0);
        end; 
    end;
      

  5.   

    呵呵, Perform(WM_NEXTDLGCTL,0,0);
      

  6.   

    搞不懂你那一个星是怎么得的。
    >>
    呵呵,人有时是一时糊涂,问题其实很简单的,发了贴后我就想起来了,要设个kepreivew,所以就自己回了个贴
      

  7.   

    偶再添一笔:
    SELECTNEXT(ACTIVECONTROL,TRUE,TRUE)
      

  8.   

    不过还有个问题,我的这个Form的Parent是一个panel,即使设了kepreivew也接收不到Key事件,怎么办?
      

  9.   

    看看
    www.eQmis.com 
    eqmis高手是什么样实现吧!!!!!!
      

  10.   

    procedure TFORM1.label1KeyPress(Sender: TObject; var Key: Char);
    begin
      if Key = #13 then
        SelectNext(Sender as TWinControl, True, True);
    end;
    在每个需要相应enter键的控件的ONKEYPRESS事件中都填写如上代码。
      

  11.   

    响应顺序是Tag的由值决定的,Tag=0且TabStop=true的控件最先响应,依次后传。
      

  12.   

    if key=#13 then
    SELECTNEXT(ACTIVECONTROL,TRUE,TRUE)