首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

回车焦点切换的有关问题

2013-07-04 
求助 回车焦点切换的问题两个输入框 textBox1,textBox2textBox1 按了回车键,焦点跳到textBox2添加了如下语

求助 回车焦点切换的问题
两个输入框 textBox1,textBox2
textBox1 按了回车键,焦点跳到textBox2

添加了如下语句
  

private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                this.textBox2.Focus();
        }

调试出现的错误
“DeviceApplication1.Form2”并不包含“textBox1_TextChanged”的定义
又添加了了语句
private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
        }

虽然没报错,但是调试的结果 textBox1 即使按了回车键,也跳转不到textBox2
求帮助
[解决办法]
this.textBox1.TextChanged += new EventHandler(textBox1_TextChanged);
这句话放到构造函数中
[解决办法]
 
20分好容易啊,快散分吧!


private void TextBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
 {
        if ((Asc(e.KeyChar) == 13))
      {
            TextBox2.Focus();
            e.Handled = false;
      }
    }
[解决办法]
直接用下面代码即可。
private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SendKeys.Send("{Tab}");


            }
        }

热点排行