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

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

    I don't know if the onChange() only exists in an older version of c#, but I can't find it!

    The following works for detecting when a user either hits the Enter key, or tabs out of the TextBox, but only after changing some text:

        //--- this block deals with user editing the textBoxInputFile --- //
        private Boolean textChanged = false;
        private void textBoxInputFile_TextChanged(object sender, EventArgs e) {
            textChanged = true;
        }
        private void textBoxInputFile_Leave(object sender, EventArgs e) {
            if (textChanged) {
                fileNameChanged();
            }
            textChanged = false;
        }
        private void textBoxInputFile_KeyDown(object sender, KeyEventArgs e) {
            if (textChanged & e.KeyCode == Keys.Enter) {
                fileNameChanged();
            }
            textChanged = false;
        }
        //--- end block  --- //
    

提交回复
热议问题