2009-10-28 64 views
2

在我的應用程序的一種形式中,我們通過向表單添加框架來添加數據集。對於每一幀,我們希望能夠通過按Enter鍵從一個編輯(Dev Express Editors)控件移動到下一個編輯。到目前爲止,我在控件的KeyPress和KeyUp事件中嘗試了四種不同的方法。如何移動到框架內的下一個控件?

  1. SelectNext(TcxCurrencyEdit(Sender), True, True); // also base types attempted

  2. SelectNext(Sender as TWinControl, True, True);

  3. Perform(WM_NEXTDLGCTL, 0, 0);

  4. f := TForm(self.Parent); // f is TForm or my form c := f.FindNextControl(f.ActiveControl, true, true, false); // c is TWinControl or TcxCurrencyEdit if assigned(c) then c.SetFocus;

沒有這些方法都工作在Delphi 5中。任何人都可以指導我做這個工作嗎?謝謝。

回答

3

這工作在Delphi 3,5和6:

設置窗體的KeyPreview屬性來真正。

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); 
begin 
    If (Key = #13) then 
    Begin 
    SelectNext(ActiveControl as TWinControl, True, True); 
    Key := #0; 
    End; 
end; 
+0

不知道爲什麼它的工作原理碰撞達到時形成的水平,但我猜它與框架的有限的交互能力做到。雖然工作得很好,謝謝。 – 2009-10-29 15:22:40

3

我發現一個老項目,當用戶按下回車鍵時,捕獲CM_DIALOGKEY消息,然後它觸發VK_TAB鍵。它適用於多個不同的控件。

interface 
... 
    procedure CMDialogKey(var Message: TCMDialogKey);message CM_DIALOGKEY; 

implementation 
... 

procedure TSomeForm.CMDialogKey(var Message : TCMDialogKey); 
begin 
    case Message.CharCode of 
    VK_RETURN : Perform(CM_DialogKey, VK_TAB, 0); 
    ... 
    else 
    inherited; 
    end; 
end; 
+0

作品中更多的組件在較低水平確實更好了 – user2092868 2013-08-10 13:15:38

1

您可以在窗體上放置一個TButton,使它變小,並將其隱藏在某個其他控件下。默認屬性設置爲true(這使得它越來越回車鍵),將以下到OnClick事件:

SelectNext(ActiveControl, true, true); 
1

事件onKeyPress像其他任何形式一樣被觸發。

問題是程序執行(wm_nextdlgctl,0,0)在框架內不起作用。

您必須知道激活的控件才能激發適當的事件。

procedure TFrmDadosCliente.EditKeyPress(Sender: TObject; var Key: Char); 
var 
    AParent:TComponent; 
begin 
    if key = #13 then 
    begin 
    key := #0; 

    AParent:= TComponent(Sender).GetParentComponent; 

    while not (AParent is TCustomForm) do 
     AParent:= AParent.GetParentComponent; 

    SelectNext(TCustomForm(AParent).ActiveControl, true, true); 
    end; 
end; 
相關問題