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

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

2012-01-24 
C#如何实现在textBox1上敲回车时光标跳至button2 ?privatevoidtextBox1_KeyPress(objectsender,KeyPressEv

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();
}
}

}

热点排行