各位大大,求教:当我的焦点在“Textbox1”控件上时,按“Enter”,自动跳转到TextBox3控件上,再按“Enter”,跳转到TextBox4控件上,这样的程序代码如何写?

解决方案 »

  1.   

    设置 TextBox 控件的 TabIndex  ,按 Tab建 就可以自己跳了
      

  2.   

    设置TextBox 的TabIndex 属性,索引从 0 开始,按 Tab 键,就会自动安装 TabIndex的顺序跳了。
      

  3.   

    例子:private void txtPwd_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode ==Keys.Enter)
                {
                    this.文本框.Focus();
                }
            }
      

  4.   

    private   void   textBox1_KeyDown(object   sender,   System.Windows.Forms.KeyEventArgs   e) 

    if(e.KeyCode==Keys.Enter) 

    SendKeys.Send( "{TAB} "); 


    注意设定好你的tab顺序
      

  5.   


    // <summary>
            /// Enter按下事件
            /// </summary>
            /// <param name="sender">源对象</param>
            /// <param name="e">事件参数</param>
            protected virtual void OnPageDataFormKeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter )
                {
                    this.SelectNextControl((Control)this.ActiveControl, true, true, true, false);
                }
            }你必须在设计器上,排列好控件Tab顺序!