Enter key press in C#

前端 未结 14 715
臣服心动
臣服心动 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:43

    You could use this code:

    abc_KeyDown(abc, new KeyEventArgs(Keys.Enter));
    
    0 讨论(0)
  • 2020-12-01 06:46

    KeyChar is looking for an integer value, so it needs to be converted as follows:

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToInt16(Keys.Enter))
            {
                MessageBox.Show("Testing KeyPress");
            }
        }
    
    0 讨论(0)
提交回复
热议问题