.NET TextBox - Handling the Enter Key

前端 未结 4 788
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 16:32

What is definitively the best way of performing an action based on the user\'s input of the Enter key (Keys.Enter) in a .NET TextBox, assuming owne

4条回答
  •  猫巷女王i
    2020-12-03 17:27

    You can drop this into the FormLoad event:

    textBox1.KeyPress += (sndr, ev) => 
    {
        if (ev.KeyChar.Equals((char)13))
        {
            // call your method for action on enter
            ev.Handled = true; // suppress default handling
        }
    };
    

提交回复
热议问题