.NET ---文本框控件 - 等待,直到用户完成输入 [英] .NET --- Textbox control - wait till user is done typing
问题描述
大家好,
有一个内置的方式来知道当用户完成输入到一个文本框? (之前打标签,或者移动鼠标),我有发生在TextChanged事件数据库查询,一切完美的作品。然而,我注意到,有一点当然是滞后的,因为如果用户正在迅速输入到文本框中的程序正忙做的每个字符的查询。那么,我希望的是一个方法,如果用户完成输入。因此,如果他们键入A,并停止再一个事件触发。但是,如果他们输入一路在y KEYUP后,事件触发。
Is there a built in way to know when a user is done typing into a textbox? (Before hitting tab, Or moving the mouse) I have a database query that occurs on the textchanged event and everything works perfectly. However, I noticed that there is a bit of lag of course because if a user is quickly typing into the textbox the program is busy doing a query for each character. So what I was hoping for was a way to see if the user has finished typing. So if they type "a" and stop then an event fires. However, if they type "all the way" the event fires after the y keyup.
我有一些想法四处传播我的头,但我敢肯定他们是不是最有效的。像测量时间自上次textchange事件,如果这是>大于一定值,那么它将继续运行的我的程序的其余部分。
I have some ideas floating around my head but I'm sure they aren't the most efficient. Like measuring the time since the last textchange event and if it was > than a certain value then it would proceed to run the rest of my procedures.
让我知道你在想什么。
语言:VB.NET 框架:NET 2.0
Language: VB.NET Framework: .Net 2.0
- 编辑澄清做键入
--Edited to clarify "done typing"
推荐答案
办法一:
-
创建一个
定时器
用的间隔
X毫秒
间隔应约300毫秒;多按键,而且也是合理的时间之间的正常时间整理和发生的更新之间的等待时间
The interval should be about 300ms; more than a normal time between keystrokes, and also reasonable time to wait between finishing and the update occurring
在输入的框TextChanged
时,停止()
然后启动()
的定时器
这将重新启动定时器
如果已在运行,因此如果用户不断输入以正常速度,每一次变化都会重新开始计时。
This will restart the Timer
if it is already running, so if the user keeps typing at a normal rate, each change will restart the timer.
在定时器的勾选
时,停止()
的定时器
并执行长事务
In the timer's Tick
event, Stop()
the Timer
and do the long transaction
可选:处理离开
和的KeyDown
事件,以便离开控制或pressing <大骨节病>输入骨节病>将停止()
的定时器
并执行长事务。
Optional: Handle the Leave
and KeyDown
events so that leaving the control or pressing Enter will Stop()
the Timer
and do the long transaction.
这将导致更新,如果文本已经改变,并且用户还没有取得英寸x毫秒为单位的任何变化。
This will cause an update if the text has changed, and the user hasn't made any changes in X milliseconds.
与测量自上次更新的方式,你正在考虑的一个问题是,如果最后一个变化是迅速做出,该更新将不会发生,并且不会有任何更改,触发另一个检查一下。
One problem with the "Measure the time since the last update" approach you're considering is that if the last change is made quickly, the update won't happen, and there won't be any subsequent changes to trigger another check.
注意:必须有文本框之间一对一的配对
ES和定时器
S;如果你打算在与多个输入这样做,我会考虑建立一个用户控件
包装此功能。
Note: There must be a one to one pairing between TextBox
es and Timer
s; if you're planning on doing this with more than one input, I'd consider building a UserControl
that wraps this functionality.
这篇关于.NET ---文本框控件 - 等待,直到用户完成输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!