开发者

How to handle complete change of the Textbox in Windows Forms?

What event I should handle to react to the completed change of the TextBox (i.e. when the user is finished 开发者_JS百科editing the content of the TextBox)?


There are several methods that you can use: Leave event, or a manual "typing stopped" event.

The Leave method is the most straight forward way of doing it, although as the event name suggests, it only happens when they TextBox looses focus, not when the user stops typing.

The TypingStopped event is something you would need to create yourself, but the basic idea of it is a short duration timer (say 500ms, but you would need to test it), which you restart on every KeyDown event of the TextBox. The timer would fire its own event and disable itself if it ever hits the end of it's timeout.

Edit: Updated to Leave event as per Hans' recommendation.


The Leave event is generally a good one for processing user input (for validation for example) as they move on to another part of the form. Just make sure that the event fires if they go from the textbox to any other UI element on your form - you may need to force a focus on the new element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜