在Enter KeyPress上导航表单中的所有文本框 [英] Navigating all textboxes in a form on Enter KeyPress

查看:55
本文介绍了在Enter KeyPress上导航表单中的所有文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向大家问好.

我有一个约有20个文本框的表单.我想使用回车按钮浏览每个文本框,但不为每个文本框的keypress事件编写代码.请给我一种替代方法,这样我就不必在每个文本框上编写代码控件的按键事件.如果可能,也请发布代码.

该站点解决了我的许多问题.希望找到下一个问题的解决方案.
Thanx

Hello to All.

I hav a form having about 20 textboxes.I want to navigate each text box using enter button,but without writting code for each textbox''s keypress event.Plz give me an alternate method,so that i dont hav to write code on each control''s keypress event.Also plz post the code if possible.

This site has solved my many problems.Hoping for a solution of my next problem.
Thanx

推荐答案

您是什么意思要导航"它们?

如果要检查它们的值,可以在按钮单击事件处理程序中简单地对其进行遍历.
what do you mean you want to "navigate" them?

If you want to check their values, you could simply iterate through them in the button click event handler.


您是否尝试过类似的操作:
Have you tried something like:
if (e.KeyChar == ‘\r’)
{
e.Handled = true;
System.Windows.Forms.SendKeys.Send("{TAB}");
}


覆盖表单的OnKeyUp或覆盖ProcessKeyTab ...

顺便说一句,你说:


Override the form’s OnKeyUp or override ProcessKeyTab...

Btw, you say:

Deepak.xip写道:
Deepak.xip wrote:

该网站解决了我的许多问题.

This site has solved my many problems.


看了您到目前为止提出的问题.发现只有一个标记为接受的答案!


Looked at the questions you had asked till now. Found only one marked as answer accepted!


当人们在没有实际测试答案是否有效的情况下将答案扔到那里时,我会喜欢它.

我假设您是说您要用户输入textbox,当他们按下Enter键时,它将带他们到下一个textbox,对吗?

覆盖表单的OnKeyUp将不起作用,因为如果您位于textbox中,则表单的OnKeyUp不会触发,因为它没有焦点.

但是,首先,请确保所有textbox都已为所需顺序设置了正确的TabIndex.然后,只需为textbox KeyUp事件编写一个进程,然后在KeyData中检查Keys.Enter.如果它是Enter键,则可以执行System.Windows.Form.SendKeys.Send("{TAB}").然后,只需将该进程处理程序添加到您要处理的每个textbox es中即可.
I love it when people throw answer out there without actually testing if it will work.

I assume that you''re saying that you want the user to be typing in a textbox and when they hit enter, it takes them to the next textbox, correct?

Overriding the form''s OnKeyUp will not work because if you are in a textbox, the form''s OnKeyUp won''t fire because it doesn''t have the focus.

But, first, make sure that your textboxes all have the correct TabIndex set for the order you want. Then, just write a single process for a textbox KeyUp event and check the KeyData for Keys.Enter. If it is the enter key, then you can do the System.Windows.Form.SendKeys.Send("{TAB}"). Then, just add that process handler to each of the textboxes that you want it to handle.


这篇关于在Enter KeyPress上导航表单中的所有文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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