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

前端 未结 15 1261
无人及你
无人及你 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:27

    Another simple solution would be to add a timer to your form, set the Interval property to 250 and then use the timer's tick event as follows:

    private void timer1_Tick(object sender, EventArgs e)
    {
        timer1.Stop();
        Calculate(); // method to calculate value
    }
    
    private void txtNumber_TextChanged(object sender, EventArgs e)
    {
        timer1.Stop();
        timer1.Start();
    }
    

提交回复
热议问题