获取输入文本时动态设置的文本框宽度的结尾 [英] get the end of the textbox width which is dynamically set while entering the text

查看:132
本文介绍了获取输入文本时动态设置的文本框宽度的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个TextBoxes.两者都是动态创建的,两者的宽度都是动态设置的.所以问题是,当我在第一个文本框中输入文本并结束时,剩余的文本应自动在另一个文本框中输入.
例如,在支票中写姓名时,当第一行填满时,我们将移至其下方给出的另一行.

谢谢.

解决方案

您需要使用javascript.跟踪第一个文本框中的字符数.当它越过固定数字(比如说50)时,将焦点放在下一个文本框上.

您可以使用任何一个事件来跟踪否".的字符类型:
onchange,onBlurr,onFocusOut,onKeyUp....下一个.不知道这段代码是否可以在ASP.NET上100%正常工作,但是我认为它应该给如何实现此目标至少一个好主意.

void textBox1_KeyDown(object sender, KeyEventArgs e)
{

Size textSize = System.Windows.Forms.TextRenderer.MeasureText(textBox1.Text, textBox1.Font, textBox1.Size, TextFormatFlags.Default);

if(textSize.Width >= textBox1.Width)
{
  textBox2.Focus();
}

}


Hi, I have two TextBoxes. Both are dynamically created and width of both are set dynamically. So problem is that when I enter text in first textbox and it gets its end then remaining text should be entered in another textbox automatically.
For example while writing name in cheque, when first line is fulled then we move to another line given below it.

Thanks.

解决方案

You need to use javascript for it. Track the number of characters in first textbox. The moment it crosses the fixed number(lets say 50), set the focus on next textbox.

You can use any one of the events to track the no. of character typed:
onchange, onBlurr, onFocusOut, onKeyUp....


Try something like this: It checks every time a user presses a key if it checks if it exceeds the textbox and if so if focusses the next one. Not sure if this code will work 100% on ASP.NET but I think it should give atleast a good idea on how this can be done.

void textBox1_KeyDown(object sender, KeyEventArgs e)
{

Size textSize = System.Windows.Forms.TextRenderer.MeasureText(textBox1.Text, textBox1.Font, textBox1.Size, TextFormatFlags.Default);

if(textSize.Width >= textBox1.Width)
{
  textBox2.Focus();
}

}


这篇关于获取输入文本时动态设置的文本框宽度的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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