Enter key press in C#

前端 未结 14 902
臣服心动
臣服心动 2020-12-01 06:06

I tried this code:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (Convert.ToInt32(e.KeyChar) == 13) 
    {
        MessageBox.S         


        
14条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 06:28

    Instead of using Key_press event you may use Key_down event. You can find this as below
    after double clicking here it will automatically this code

    private void textbox1_KeyDown(object sender, KeyEventArgs e)
        {
    
         }
    

    Problem solved now use as you want.

    private void textbox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                MessageBox.Show(" Enter pressed ");
            }
         }
    

提交回复
热议问题