[英]How to move to the next control inside a frame?
In one form of my application, we add sets of data by adding frames to the form. 在我的应用程序的一种形式中,我们通过向表单添加框架来添加数据集。 For each frame, we want to be able to move from one edit (Dev Express Editors) control to the next by pressing the Enter key. 对于每个帧,我们希望能够通过按Enter键从一个编辑(Dev Express Editors)控件移动到下一个控件。 So far, I have tried four different methods in my control's KeyPress and KeyUp events. 到目前为止,我已经在我的控件的KeyPress和KeyUp事件中尝试了四种不同的方法。
SelectNext(TcxCurrencyEdit(Sender), True, True); // also base types attempted
SelectNext(Sender as TWinControl, True, True);
Perform(WM_NEXTDLGCTL, 0, 0);
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;
None of these methods are working in Delphi 5. Can anyone guide me towards getting this working? 这些方法都不适用于Delphi 5.任何人都可以指导我使用它吗? Thanks. 谢谢。
I found one old project that catches CM_DIALOGKEY
message when user presses Enter key and then it fires VK_TAB
key . 当用户按下Enter键然后它触发VK_TAB
键时,我找到了一个捕获CM_DIALOGKEY
消息的旧项目。 It works with number of different controls. 它适用于许多不同的控件。
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;
This works in Delphi 3, 5 and 6: 这适用于Delphi 3,5和6:
Set form's KeyPreview property to True. 将表单的KeyPreview属性设置为True。
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
If (Key = #13) then
Begin
SelectNext(ActiveControl as TWinControl, True, True);
Key := #0;
End;
end;
The event onKeyPress is trigered like any other form. 事件onKeyPress像任何其他形式一样被触发。
The problem is that the procedure perform(wm_nextdlgctl,0,0) doen't work inside the frame. 问题是程序执行(wm_nextdlgctl,0,0)在框架内不起作用。
You must know the active control to triger the proper event. 您必须知道主动控件才能使正确的事件发生变化。
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;
You can place a TButton on the form, make it small and hide it under some other control. 您可以在表单上放置TButton,将其缩小并将其隐藏在其他控件下。 Set the Default property to true (that makes it getting the Enter key) and place the following into the OnClick event: 将Default属性设置为true(使其获得Enter键)并将以下内容放入OnClick事件:
SelectNext(ActiveControl, true, true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.