Delphi:如何将向上箭头键盘快捷键分配给操作/菜单项,并使其保持实际状态以导航列表控件(ListBox/VTV)?
请帮助我:如何为操作或菜单项分配向上箭头键盘快捷键,并同时保持其实际导航列表控件(例如列表框/虚拟树视图/其他)?
谢谢!
Please assist me: How to assign an up arrow keyboard shortcut to action or menu item, and keep it actual for navigating the list control (e.g. ListBox/Virtual Treeview/other) at the same time?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您评论:
但这当然是可能的,只是这样做不是一个好主意,并违反 Windows 用户体验交互指南。
但如果您决定实施它,请按以下步骤操作。在包含操作组件的表单类中重写以下方法:
并且在其中您可以防止向上和向下键触发它们是快捷方式的操作:
请注意,您也应该测试正确的切换状态,并检查您的代码不会破坏用户期望的任何其他窗口行为,例如使用箭头键移动窗口。
You comment:
but it certainly is possible, it just isn't a good idea to do it, and against the Windows User Experience Interaction Guidelines.
But if you're set on implementing it, here's how. Override the following method in your form class that contains the action components:
and in it you can prevent the Up and Down key from triggering the actions they are shortcuts for:
Note that you should test for the correct shift state too, and check that your code doesn't break any other window behaviour users expect, like moving of the window with the arrow keys.
在表单属性上设置
KeyPreview := true
然后在表单的 KeyUp 事件上写入事件来检查是否按下了向上键并使其调用菜单项(在本例中菜单项称为 Action1):
如果您需要执行 Action1,即使当前控件不是列表框,请删除
IF
语句的and
部分On the form properties set
KeyPreview := true
then on KeyUp event of the form write event to check if you Up key is pressed and make it call the menu item (on this case menu item called Action1):
If you need the Action1 to be executed even if they Current Control isn't the listbox, remove the
and
part of theIF
statement