将下一个控件集中在覆盖的 KeyUp 中的 Enter - 上

发布于 2024-11-25 15:55:15 字数 732 浏览 2 评论 0原文

我有一个扩展 TEdit 的自定义类:

  TMyTextEdit = class (TEdit)
   private
     fFocusNextOnEnter: Boolean;
   public
    procedure KeyUp(var Key: Word; Shift :TShiftState); override;
   published
     property FocusNextOnExnter: Boolean read fFocusNextOnEnter
                                 write fFocusNextOnEnter default false;
  end;

在 KeyUp 过程中我这样做:

procedure TMyTextEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
  inherited;

  if FocusNextOnExnter then
    if Key = VK_RETURN then 
      SelectNext(Self as TWinControl, True, false);
end;

但它并没有将焦点转移到下一个控件。我尝试过,

if Key = VK_RETURN then
      Key := VK_TAB;

但它也不起作用。我缺少什么?

I have my custom class that extends TEdit:

  TMyTextEdit = class (TEdit)
   private
     fFocusNextOnEnter: Boolean;
   public
    procedure KeyUp(var Key: Word; Shift :TShiftState); override;
   published
     property FocusNextOnExnter: Boolean read fFocusNextOnEnter
                                 write fFocusNextOnEnter default false;
  end;

In The KeyUp procedure I do:

procedure TMyTextEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
  inherited;

  if FocusNextOnExnter then
    if Key = VK_RETURN then 
      SelectNext(Self as TWinControl, True, false);
end;

But it isn't moving focus to the next control. I tried to

if Key = VK_RETURN then
      Key := VK_TAB;

but it isn't working either. What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烟火散人牵绊 2024-12-02 15:55:15

SelectNext 选择下一个同级子控件,即。您需要在编辑的父级上调用它:

type
  THackWinControl = class(TWinControl);

if Key = VK_RETURN then
  if Assigned(Parent) then
    THackWinControl(Parent).SelectNext(Self, True, False);

SelectNext selects next sibling child control, ie. you need to call it on your edit's parent:

type
  THackWinControl = class(TWinControl);

if Key = VK_RETURN then
  if Assigned(Parent) then
    THackWinControl(Parent).SelectNext(Self, True, False);
森林散布 2024-12-02 15:55:15

这是记录的 PostMessage 方法(使用消息):)

procedure TMyEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
  inherited;
  if FocusNextOnEnter then
    if Key = VK_RETURN then begin
      PostMessage(GetParentForm(Self).Handle, wm_NextDlgCtl, Ord((ssShift in Shift)), 0);
      Key := 0;
    end;
end;

Here's the PostMessage approach (uses Messages) for the record :)

procedure TMyEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
  inherited;
  if FocusNextOnEnter then
    if Key = VK_RETURN then begin
      PostMessage(GetParentForm(Self).Handle, wm_NextDlgCtl, Ord((ssShift in Shift)), 0);
      Key := 0;
    end;
end;
回梦 2024-12-02 15:55:15
procedure TMyEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin

  inherited;

  if FocusNextOnExnter and Focused and (Key = VK_RETURN) then 

  begin

    Perform(CM_DIALOGKEY, VK_TAB, 0);

    Key := 0;

  end;

end;
procedure TMyEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin

  inherited;

  if FocusNextOnExnter and Focused and (Key = VK_RETURN) then 

  begin

    Perform(CM_DIALOGKEY, VK_TAB, 0);

    Key := 0;

  end;

end;
自此以后,行同陌路 2024-12-02 15:55:15

THackWinControl 可以避免,并且让它变得更好:

SelectNext(ActiveControl as TWinControl, True, ssShift in Shift);

问题是它仍然下拉组合框选项。

我正在努力。

The THackWinControl can be avoided, and to make it nice:

SelectNext(ActiveControl as TWinControl, True, ssShift in Shift);

Problem is it still pull down combobox choices.

I'm working on that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文