我要实现的功能是:
    我有很多文本框,在我输入完一个文本框的值后按下Enter键时,它会自动切换到下个文本框?

解决方案 »

  1.   


            protected override bool ProcessCmdKey(ref Message msg, Keys keyData)//重写键盘回车代码
            {
                if (keyData == Keys.Enter)
                {
                    System.Windows.Forms.SendKeys.Send("{TAB}");
                    return true;
                }
                else
                    return base.ProcessCmdKey(ref msg, keyData);
            }写上这个
      

  2.   


    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown, TextBox2.KeyDown, TextBox3.KeyDown,……
            If e.KeyData = Keys.Enter Then
                Me.SelectNextControl(Me, False, True, False, True)
            End If
        End Sub
      

  3.   

    在textbox的KeyDown事件中设置private void textbox1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyValue == 13)
                {
                    textbox2.Focus();
                }
            }
      

  4.   

    使用KeyPress  事件  private void Form1_Load(object sender, EventArgs e)
            {
                this.KeyPreview = true;
                this.KeyPress += new KeyPressEventHandler(Form1_KeyPress);
                
              
            }        void Form1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == '\r')
                {
                    SendKeys.Send("\t");                //或则textBox1.Focus();
                    e.Handled = false;
                }
            }
      

  5.   

    使用KeyPress  事件  private void Form1_Load(object sender, EventArgs e)
            {
                this.KeyPreview = true;
                this.KeyPress += new KeyPressEventHandler(Form1_KeyPress);
                
              
            }        void Form1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == '\r')
                {
                    SendKeys.Send("\t");                //或则textBox1.Focus();
                    e.Handled = true;
                }
            }
      

  6.   


    //给所有的textbox commobox订阅 EnterKeyDown事件foreach(Control ctrl in this.Controls) 

        if ((ctrl is TextBox) || (ctrl is ComboBox))
        { 
            ctrl.KeyDown += new KeyEventHandler(EnterKeyDown); 
        } 
    }
    private void EnterKeyDown(object sender, KeyEventArgs e) 

        if(e.KeyCode==Keys.Enter) 
        { 
            SendKeys.Send("{TAB}"); 
        } 

      

  7.   

    楼上各位的方法均可。不过你可能并不想把所有enter键变成tab键吧?
      

  8.   

    你可以查出Tab的ASCII码值然后将它的值赋给Enter键如果你不想全部都变成Tab你可以做下判断当控件是TEXT时就赋值否则为Enter的ASCII码值这样你可以去试试!