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; 
相关问题