读书人

C#怎么实现在textBox1上敲回车时光标跳

发布时间: 2012-01-24 23:11:54 作者: rapoo

C#如何实现在textBox1上敲回车时光标跳至button2 ?
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (textBox1.Text.Trim() != " ")
{
if //敲回车键 ....这里怎么写 ?
{
button2.Focus();
}
}
}

[解决办法]
if (e.KeyChar == 13)

[解决办法]
if (textBox1.Text.Trim() != " ")
{
if (e.KeyChar == (char)13)
{
button2.Focus();
}
}

[解决办法]
用Key_Down事件,别用Key_Press
[解决办法]
if (textBox1.Text.Trim() != null)
{
if (e.KeyCode==Keys.Enter )
{
textBox2.Focus();
}
}
[解决办法]
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (textBox1.Text.Trim() != null)
{
if (e.KeyCode==Keys.Enter )
{
textBox2.Focus();
}
}

}

读书人网 >C#

热点推荐