如何使用Enter键而不是Tab键在窗体上的控件之间导航 [英] How to navigate between controls on form using Enter Key instead of Tab key

查看:108
本文介绍了如何使用Enter键而不是Tab键在窗体上的控件之间导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我想使用"Enter"键而不是"Tab"键在文本框,组合框等控件之间导航.

In my project on from i want to navigate between controls like textbox,combobox etc using ''Enter'' Key Instead of ''Tab'' key.
Have Any Setting or property is avialable for it?

推荐答案

我完全同意JSOP.您想要做的是非标准的.

但是 ,如果您绝对必须这样做(并在决定使用前请仔细考虑),请按照以下步骤操作.

1.处理要在其上发生的控件的OnKeyDownOnKeyPress事件.在MSDN上查找事件.
2.测试回车键(MSDN页面从内存中显示如何执行此操作).
3.在您决定使用的处理程序中的伪代码
I entirely agree with JSOP on this. What you want to do is non-standard.

However, if you absolutely must do it (and please think carefully before you decide to) follow these steps.

1. Handle either the OnKeyDown or OnKeyPress event for the controls that you want this to happen on. Look up the events on MSDN.
2. Test for the enter key (from memory the MSDN pages show you how to do this).
3. pseudo code in whichever handler you decide to use
if key is enter key
    SelectNextControl(sender, true, false, false, true); <==== real code
end if



再次在MSDN上查找SelectNextControl以了解参数的用途.

祝你好运! :-)



Once again look up SelectNextControl on MSDN for the uses of the parameters.

Good luck! :-)


在我的情况下,我希望Enter键的功能与Tab键完全一样,所以我发明了此事件:

In my situation I wanted the enter key to function exactly like the tab key so I invented this event:

private void WriteEnglish_KeyPress(object sender, KeyPressEventArgs e)
       {
           if (e.KeyChar == "\r"))
           {
               SendKeys.Send("\t");
           }
       }



然后,我依靠TabOrder来控制下一个焦点.



Then I depend on the TabOrder to control where focus goes next. It works great for me.


那是一个非标准的接口. Windows的全部目的是为所有应用程序提供一个通用接口.

实现此目的的唯一方法是吃掉Tab事件,并通过检查所有控件的Tab顺序并确定设置为Tab顺序的下一个控件,手动确定要移动到哪个控件,从而处理Enter键事件.制表符.

同样,对于Windows应用程序来说,这是非常奇怪的行为,您应该期望用户将其报告为错误,或者至少将其报告为令人讨厌的地狱.
That''s a non-standard interface. The whole point of Windows is to provide a common interface for all applications.

The only way you could accomplish this is by eating the tab event, and handling the enter key event by manually determining which control to move to by examining the tab order of all controls and moving to the next control in the tab order that is set as a tab stop.

Again, this is extremely odd behavior for a Windows app, and you should expect users to report it as a bug, or at the very least, annoying as hell.


这篇关于如何使用Enter键而不是Tab键在窗体上的控件之间导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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