如何只有当用户停止输入处理TextChanged事件? [英] How to handle the TextChanged event only when the user stops typing?
问题描述
我有一个文本框
与框TextChanged
事件接线。最后,它正在查询到SQL数据库,所以我想限制的查询数量。
I have a TextBox
with a TextChanged
event wired up. In the end it is making a query to a SQL database, so I want to limit the number of queries.
我只想使查询的如果用户没有按下发言权一个键青霉> .. 300毫秒左右。如果由于某种原因,前面的查询仍在执行,我需要取消,然后发出一个新的查询。
I only want to make the query if the user hasn't pressed a key in say .. 300 milliseconds or so. If for some reason the previous query is still executing, I would need to cancel that, and then issue a new query.
推荐答案
每一个按键后创建一个 System.Windows.Forms.Timer
和复位(如停止然后再启动它)。如果定时器事件被触发,禁止定时器。
Create a System.Windows.Forms.Timer
and reset it (e.g. stop then start it) after every keypress. If the timer event is triggered, disable the timer.
这篇关于如何只有当用户停止输入处理TextChanged事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!