没有特定事件,要响应KeyPress再判断按下的是不是回车

解决方案 »

  1.   

    有啊,用Keypress事件判断
    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if (e.KeyChar=13)    //回车
    { }
    }
      

  2.   

    private void textBox6_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
                                if(e.KeyValue==13)
    {
    //响应事件
    }

    }
      

  3.   

    可以的,用keypress事件来判断。按下的时候触发该事件:private void keypressed(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if (e.KeyChar==(Char)13)    //按下了回车键
    {
    MessageBox.Show("你按了回车键!");
    }
    }然后在窗体的构造函数里加一行
    this.textBox1.KeyPress += new KeyPressEventHandler(keypressed);//触发按下键后的事件
    就可以了。