C# wait for user to finish typing in a Text Box

前端 未结 15 1267
无人及你
无人及你 2020-11-27 18:16

Is there a way in C# to wait till the user finished typing in a textbox before taking in values they have typed without hitting enter?

Revised this question a little

15条回答
  •  甜味超标
    2020-11-27 18:26

    A coworker of mine suggested a solution using Rx and event throttling:

    var FindDelay = 500;//milliseconds
    //textBox is your text box element
    Observable.FromEventPattern(textBox, "TextChanged")
        .Select(ea => ((TextBox) ea.Sender).Text)
        .DistinctUntilChanged()
        .Throttle(TimeSpan.FromMilliseconds(FindDelay))
        .Subscribe(text => { 
            //your handler here 
        });
    

提交回复
热议问题