Press enter in textbox to and execute button command

前端 未结 10 875
时光取名叫无心
时光取名叫无心 2021-01-30 13:40

I want to execute the code behind my Search Button by pressing Enter. I have the Accept Button property to my search button. However, when i place my button as NOT vi

10条回答
  •  逝去的感伤
    2021-01-30 13:55

    You can handle the keydown event of your TextBox control.

    private void textBox1_KeyDown(object sender, KeyEventArgs e)
    {
        if(e.KeyCode==Keys.Enter)
        buttonSearch_Click(sender,e);
    }
    

    It works even when the button Visible property is set to false

提交回复
热议问题