在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:
该网站解决了我的许多问题.
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 atextbox
and when they hit enter, it takes them to the nexttextbox
, correct?
Overriding the form''sOnKeyUp
will not work because if you are in atextbox
, the form''sOnKeyUp
won''t fire because it doesn''t have the focus.
But, first, make sure that yourtextbox
es all have the correctTabIndex
set for the order you want. Then, just write a single process for atextbox
KeyUp
event and check theKeyData
forKeys.Enter
. If it is the enter key, then you can do theSystem.Windows.Form.SendKeys.Send("{TAB}")
. Then, just add that process handler to each of thetextbox
es that you want it to handle.