将下一个控件重点放在输入-覆盖的KeyUp中 [英] Focus next control on enter - in overridden KeyUp

查看:81
本文介绍了将下一个控件重点放在输入-覆盖的KeyUp中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有扩展TEdit的自定义类:

I have my custom class that extends T

  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过程中,我这样做:

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?

推荐答案

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

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);

这篇关于将下一个控件重点放在输入-覆盖的KeyUp中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆