我在Form中將KeyPreview設為真,在事件的OnKeyPress中定義如下:
procedure Tlogin01.FormKeyPress(Sender: TObject; var Key: Char);
begin
    if key=#13 then
     begin
        key:=#0;
        perform(WM_NEXTDLGCTL,0,0);
     end;
end;
可在執行時按Enter還是不行,一定要按Tab鍵才可移動光標,請問這到底是什麼問題,在Edit中我都是這樣用的,難道在DbEdit中就不行嗎,請高手指點,謝謝

解决方案 »

  1.   

    你为什么要那么做,有更简单的方法了,再DBEDIT1得KeyPress中加事件procedure Tlogin01.DBEdit1KeyPress(Sender: TObject; var Key: Char);
    begin
        if key=#13 then
         begin
            key:=#0;
            //perform(WM_NEXTDLGCTL,0,0);
            dbEdit2.setfocus; //光标移到DBEDIT2
         end;
    end;
      

  2.   

    這樣做的話不是每個DBEdit都有加這樣的語句不是很麻煩嗎?
      

  3.   

    if key = #13 then
        PostMessage(ActiveControl.Handle, wm_keydown, vk_tab, 0);
    这样看看行不行
      

  4.   

    form有个keypreview,改成true即可
      

  5.   

    if key = #13 then
        PostMessage(ActiveControl.Handle, wm_keydown, vk_tab, 0);