如题,如何实现按Enter焦点跳到指定控件
小弟我初来报道,自学中
以后还望各高手不胜指点
在VS2008中

解决方案 »

  1.   


    //在KeyDown事件中判断    if (e.KeyCode == Keys.Enter)
        {
            你要得到焦点控件的ID.Focus();
        }
      

  2.   

    http://topic.csdn.net/u/20090702/21/421386f0-03ae-4f78-aafd-9029315dff07.html
      

  3.   

    在A控件敲回车焦点到B控件,在A控件的KeyDown事件里写如下代码,
    if(e.KeyCode == Keys.Enter)
    {
       B.Focus();
    }
      

  4.   

    有很多方法可以实现,
    右键控件,属性页,点“闪电”图标(控件的所有事件都在这)其中有几个事件都可以做这个KeyPress ---控件获得焦点时,用户按下或释放某键
    KeyUp---控件获得焦点时,用户释放某键,抬起的时候
    下面举两个例子 都是 textBox1 输入回车 跳到 textBox2上 private void textBox1_KeyUp(object sender, KeyEventArgs e)
            {
                //keyUp 判断是code 
                if (e.KeyCode == Keys.Enter)
                {
                    this.textBox2.Focus();
                }
            }
            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                //keypress 判断是输入的字符 \r是回车
                if (e.KeyChar == '\r')
                {
                    this.textBox2.Focus();
                }
            }
      

  5.   

    另增加点解释
    private void textBox1_KeyUp(object sender, KeyEventArgs e)
    这个方法中  sender 是当前事件 的控件对象 e是键盘输出的字符如果想用回车控制 焦点调整 有几种方法
    1、设置TAB 的顺序,然后 写下回执执行TAB 的代码就行了
    2、是写一共用的KeyPress事件
    由于你选择代码控制,我重点介绍第2个
       首先 、写公共的 keypress方法,下面有简单例子。
       然后、将所有要控制的控件 的 KeyPress事件都设置到这个事件上。  private void keypress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar != '\r')
                {
                    e.Handled = true;
                    return;
                }
                if (sender == textBox1)
                {
                    this.textBox2.Focus();
                }
                else if (sender == textBox2)
                {
                    textBox3.Focus();
                }
                else if (sender == textBox3)
                {
                    textBox4.Focus();
                }
            }
     
      

  6.   

    谢zhy2003119高手解答,彻底让我明白了,扩展了“事件”;嘿,相信对自己摸索新来的在碰到同类问题的人也会有所帮助