简体   繁体   English

如何移动到框架内的下一个控件?

[英]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事件中尝试了四种不同的方法。

  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;

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.

相关问题 如何通过拖动面板或框架或其中的任何组件来移动面板或框架? - How to move a panel or frame by dragging it or any component inside it? Delphi-如何移动控件并刷新它 - Delphi - how to move a control and refresh it (Delphi FMX)如何在TabControl.TabItem内部刷新框架对象而又不失去对窗口的控制? - (Delphi FMX) How can I refresh my Frame Object inside a TabControl.TabItem without losing control of the window? Delphi,如何在鼠标移动时显示重叠控件 - Delphi, How to show an overlayed control on mouse move FireMonkey:如何将下一个控件集中在 vkReturn 上? - FireMonkey: How to focus the next control on vkReturn? 表单创建 2 帧 - 如何从第 1 帧内部调用第 2 帧中的过程? - Form creates 2 Frames - How to call procedure in Frame 2 from inside Frame 1? TcxGridDBBandedColumn如何在带内移动而不在带外移动 - TcxGridDBBandedColumn how to move inside band and not move outside of the band 如何在 Firemonkey Delphi 的 TListView 中选择项目后移至下一个选项卡 - How to move to Next Tab upon selection of an Item in TListView in Firemonkey Delphi 编辑Delphi表单时如何拦截控件移动 - How to intercept control move when editing a Delphi form 如何在运行时使用键盘移动 Delphi 中的控件? - How can I move a control in Delphi at runtime using the keyboard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM