关于Winform的问题--TextBox 输入字符以后按回车键Enter转到下一个TextBox框,怎么实现?

时间:2022-09-12 16:56:58
如题,up
一个TextBox控件输入字符以后按回车键Enter转到下一个TextBox框,怎么实现?

12 个解决方案

#1


类似tabIndex,写keypress事件吧,没有简单方法

#2


引用 1 楼 xhan2000 的回复:
类似tabIndex,写keypress事件吧,没有简单方法

#4


private void txtOrderNO_Enter(object sender, System.EventArgs e){}
能不能在第一个的textBox控件中Enter事件中写?
我自己顶

#5


1楼 right

#6


楼上的有写过?

#7


设置form的KeyPreview = true,然后调整form上组件的tabIndex,最后在form的KeyPress事件里加入以下代码

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == 13) 
    {
        SendKeys.Send("{TAB}");
    }
}

#8


楼上老兄的答案最好,网页里用JS写的差不多

#9


private void Form1_KeyPress(object sender, KeyPressEventArgs e) 

    if (e.KeyChar == 13) 
    { 
        textBox2.select();
        textBox2.Focus();
    } 
}

#10


引用 7 楼 hongqi162 的回复:
设置form的KeyPreview = true,然后调整form上组件的tabIndex,最后在form的KeyPress事件里加入以下代码 

private void Form1_KeyPress(object sender, KeyPressEventArgs e) 

    if (e.KeyChar == 13) 
    { 
        SendKeys.Send("{TAB}"); 
    } 
}

没什么好方法了,记的把控件的INDEXID设置好。。按你要的顺序给好数字。。

#11


写个回车事件!!

#12


private void TextBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)

{

    if (e.keychar==0xd) //0x8 为退格键;0xd为回车键;0x30—0x39 为数字键0-9

    {

     //触发事件
     TextBox2.Focus();

   }

}
 
这个办法最笨

谢谢10楼的答复,恩,很简单。结贴了,非常感谢

#1


类似tabIndex,写keypress事件吧,没有简单方法

#2


引用 1 楼 xhan2000 的回复:
类似tabIndex,写keypress事件吧,没有简单方法

#3


#4


private void txtOrderNO_Enter(object sender, System.EventArgs e){}
能不能在第一个的textBox控件中Enter事件中写?
我自己顶

#5


1楼 right

#6


楼上的有写过?

#7


设置form的KeyPreview = true,然后调整form上组件的tabIndex,最后在form的KeyPress事件里加入以下代码

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == 13) 
    {
        SendKeys.Send("{TAB}");
    }
}

#8


楼上老兄的答案最好,网页里用JS写的差不多

#9


private void Form1_KeyPress(object sender, KeyPressEventArgs e) 

    if (e.KeyChar == 13) 
    { 
        textBox2.select();
        textBox2.Focus();
    } 
}

#10


引用 7 楼 hongqi162 的回复:
设置form的KeyPreview = true,然后调整form上组件的tabIndex,最后在form的KeyPress事件里加入以下代码 

private void Form1_KeyPress(object sender, KeyPressEventArgs e) 

    if (e.KeyChar == 13) 
    { 
        SendKeys.Send("{TAB}"); 
    } 
}

没什么好方法了,记的把控件的INDEXID设置好。。按你要的顺序给好数字。。

#11


写个回车事件!!

#12


private void TextBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)

{

    if (e.keychar==0xd) //0x8 为退格键;0xd为回车键;0x30—0x39 为数字键0-9

    {

     //触发事件
     TextBox2.Focus();

   }

}
 
这个办法最笨

谢谢10楼的答复,恩,很简单。结贴了,非常感谢