在c#.net windows应用程序中达到限制时,文本框文本如何自动移动到下一个控件? [英] how text box text automatically moving to next control when limit is reached in c# .net windows application?
本文介绍了在c#.net windows应用程序中达到限制时,文本框文本如何自动移动到下一个控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
如果在c#.net windows应用程序中达到限制时文本框文本如何自动移动到下一个控件?
请帮帮我。
先谢谢。
Ankit Agarwal
软件工程师
Hello,
How text box text automatically moving to next control when limit is reached in c# .net windows application?
Please help me.
Thanks in Advance.
Ankit Agarwal
Software Engineer
推荐答案
您好b $ b
这很容易实现:
Hi
It is really easily just do it :
<pre lang="cs">private void textBox1_TextChanged(object sender, EventArgs e)
{
if (((TextBox)sender).TextLength > 5)
SendKeys.Send("{Tab}");
}
记住你应该为你的控件设置 TabIndex
。
最好的问候。
Just remember you should set TabIndex
for your controls.
Best Regards.
Hi Ankit,
我希望你想要这个,
两个文本框, TextBox1 和 TextBox2 ,分别限制为4。 />
如果我在TextBox1中键入4个字符,那么自动焦点应该移动到TextBox2。
例如,
如果我想输入12345678。
我在TextBox1中键入 1234 ,当我按5时,焦点应该指向TextBox2并且应该在TextBox2中输入5678,我是对的吗?
如果我是对的,那么这里是你的代码
Hi Ankit,
I hope you want this,
Two text boxes, TextBox1 and TextBox2 with limit 4 respectively.
If I type 4 characters in TextBox1 then automatically focus should move to TextBox2.
For example,
If I want to type 12345678.
I type 1234 in TextBox1, When I press 5, focus should point to TextBox2 and 5678 should be entered in TextBox2, am i right?
If am right then here is the code for you
private void textBox1_TextChanged(object sender, EventArgs e)
{
//validates the length of textbox starts from 0.
if (textBox1.TextLength > 3)
{
textBox2.Focus();
}
}
我希望这会对你有所帮助。
此致,
RK
I hope this would help you a bit.
Regards,
RK
这篇关于在c#.net windows应用程序中达到限制时,文本框文本如何自动移动到下一个控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文