使用箭头键导航 [英] navigate using arrow keys

查看:92
本文介绍了使用箭头键导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望代码使用箭头键在控件中导航.
有人可以帮我吗?

Hi I want code to navigate through control using arrow key.
Can anyone help me out?

推荐答案

我不推荐这样做,因为用户通常期望使用标准行为.

您需要将所有控件放在一些数据图中,以确定哪个控件是哪个控件的左/右/上/下成员.您可以手动或自动根据屏幕上每个控件的计算位置对这些数据进行编码(非常复杂的逻辑).之后,您需要自动向每个控件添加事件KeyDown.您可以使用从窗体/窗口开始的递归遍历整个控件集或在上一步中构建的图形.该处理程序可以根据所按下的按钮(向左/向右/向上/向下)查找导航方向,以查找图表以找出哪个控件是所需方向上的相邻控件.结果可以是null,因此不需要任何操作-当前的焦点控件已经在最左边,最右边等.如果找到的相邻控件不是null,则调用它的方法Focus.

就这样.

再说一次:我不推荐它,因为用户通常期望标准行为.

—SA
I do not recommend it as the user normally expects standard behavior.

You need to put all your controls in some data graphs determine which control is a left/right/up/down member of which. You can code this data manually or automatically based calculated position of each control on screen (pretty complex logic). After that, you need to add an event KeyDown to each control automatically. You can use recursion starting from the form/window to traverse the full control set or the graph built on the previous step. This handler can find the direction of navigation based on the button pressed (left/right/up/down) lookup the graph to find out which control is the neighboring in required direction. The result can be null, so no action is required — the current focus control is already leftmost, rightmost, etc. When the found neighboring control is not null, call it''s method Focus.

That''s it.

Again: I do not recommend it as the user normally expects standard behavior.

—SA


如果我理解您的问题是对的,
您只需要设置正确的
If I understand your question right,
you just need to set correct tab order[^] and you can navigate through the controls using the arrow keys in that order.


这篇关于使用箭头键导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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