如何使 Enter 键在 Delphi FireMonkey 应用程序中充当选项卡?
以前,在 Delphi VCL 应用程序中,很容易“覆盖”组件的 onkeyup 或 onkeydown 事件上的击键,以使 Enter 键充当 TAB 键。 FireMonkey 应用程序的工作方式与 VCL 不同,那么现在应该如何执行此操作呢?
Previously in Delphi VCL applications it was easy to "over ride" the key strokes on either the onkeyup or onkeydown events of components to make the Enter key behave as a TAB key. FireMonkey applications work differently from VCL, so how should one do this now?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢 @Uwe Raabe 提供的简单解决方案,我正在编辑我的答案以提供另一个解决方案。我将把所有内容都留在这里,因为这个答案暴露了 Firemonkey 中的一些“魔法”,而这些“魔法”通常并不明显。
我需要在表单的 FormShow 事件上动态创建“TAB”功能,以节省实施时间。我需要创建一个类来处理 TNotifyEvent (OnClick)。这是我的另一个解决方案,我现在已经成功测试过。请注意,下面的代码将尝试删除 Enter 上的“默认”按钮操作,以便其正常工作。
例如,TComboBox 与 Button 解决方案的配合不太好,这里是一个使其工作的示例。
以下代码是一个过程,可以从全局库或 TDataModule 中使用它来为您提供 Enter to Tab 功能。我在输入上使用了 onkeyup 事件来测试它。
下面是它的使用示例片段
显然,您可以根据您的需要更改过程以不同的方式工作,但是我尝试通过使用 TComponent 和 TForm 作为获取 TabList 的容器来使其尽可能通用。
I'm editing my answer to provide another solution thanks to the simple solution provided by @Uwe Raabe. I'm leaving everything here as this answer exposes some of the "magic" in Firemonkey which often isn't obvious.
I needed to create the "TAB" functionality dynamically on FormShow event of a Form to save myself time on implementation. I needed to make a class to handle the TNotifyEvent (OnClick). Here is my other solution which I have tested now with success. Please note the code below will attempt to remove "Default" button action on Enter so it works.
The TComboBox for example does does not place nice with the Button solution, here is an example of making it work
The following code is a procedure which can be used from a global library or TDataModule to provide you with the Enter to Tab functionality. I used the onkeyup events on inputs to test it.
The following is an example snippet of it's use
Obviously you could change the procedure to work differently according to your needs however I have tried to make it as generic as possible by using TComponent and TForm as the container for getting the TabList.
正如我在评论中已经提到的,另一种方法是在表单上放置一个
TButton
,设置TabStop = False
和Default = True
。使其变小并将其隐藏在另一个控件下。在按钮的 OnClick 事件中执行以下代码:
请注意,具有焦点的任何其他按钮都优先于该按钮,因此保留了预期的行为。
As I already mentioned in a comment, another way is to drop a
TButton
on the form, setTabStop = False
andDefault = True
. The make it small and hide it under another control.In the OnClick event of the button execute the following code:
Note that any other button having focus takes precedence over this, so the expected behavior is preserved.