Delphi:如何使ENTER键用作TFrame中的TAB键 [英] Delphi: How to make ENTER key works as TAB key in TFrame

查看:125
本文介绍了Delphi:如何使ENTER键用作TFrame中的TAB键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个框架和一些控件(编辑,按钮等)。如何在框架控件上的任意位置截取ENTER键并转换为TAB键(考虑到SHIFT状态)?

I have a Frame and some controls on them (edits, buttons, etc.). How to intercept pressing of ENTER key anywhere on a frame control and translate in to TAB key (taking into account SHIFT status)?

推荐答案

下面是一些示例代码,这些代码将处理框架上的消息,以便在按下 Enter 时能够导航到下一个控件。请注意,此示例不会将 Enter 键修改为 Tab 键。相反,它选择下一个控件并阻止进一步处理按键消息。

Here's some example code that would handle a message on the frame to be able to navigate to the next control when Enter is pressed. Note that this sample does not modify the Enter key to become a Tab key. Instead it selects the next control and prevents further processing of the key down message.

还要注意,代码可能需要进一步调整。一个原因是,如果任何控件实际上需要处理 Enter 键,例如 TMemo ,则需要添加一个例外。其次,导航被包裹在框架中,即,在最后一个框架控件之后,第一个框架控件被聚焦-不在窗体上而不是在框架上。对于这些,您可能想为消息返回添加条件,如果您希望在某种条件下进行默认处理,只需调用继承而无需做任何其他事情即可。

Also note that the code may require further tweaking. One for, if any of the controls actually need to process the Enter key, for instance a TMemo, you need to add an exception. Second for, the navigation is wrapped in the frame, i.e. after the last frame control the first frame control is focused - not a control on the form and not on the frame. For these, you might want to add conditions for the message return, if you want default processing on some condition simply call inherited without doing any other thing.

type
  TFrame2 = class(TFrame)
    ...
  protected
    procedure CMChildKey(var Message: TCMChildKey); message CM_CHILDKEY;
  end;

..

procedure TFrame2.CMChildKey(var Message: TCMChildKey);
begin
  if Message.CharCode = VK_RETURN then begin
    SelectNext(Screen.ActiveControl, not Bool(GetKeyState(VK_SHIFT) and $80), True);
    Message.Result := 1;
  end else
    inherited;
end;

这篇关于Delphi:如何使ENTER键用作TFrame中的TAB键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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