Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown, TextBox2.KeyDown, TextBox3.KeyDown,…… If e.KeyData = Keys.Enter Then Me.SelectNextControl(Me, False, True, False, True) End If End Sub
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)//重写键盘回车代码
{
if (keyData == Keys.Enter)
{
System.Windows.Forms.SendKeys.Send("{TAB}");
return true;
}
else
return base.ProcessCmdKey(ref msg, keyData);
}写上这个
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown, TextBox2.KeyDown, TextBox3.KeyDown,……
If e.KeyData = Keys.Enter Then
Me.SelectNextControl(Me, False, True, False, True)
End If
End Sub
{
if (e.KeyValue == 13)
{
textbox2.Focus();
}
}
{
this.KeyPreview = true;
this.KeyPress += new KeyPressEventHandler(Form1_KeyPress);
} void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
{
SendKeys.Send("\t"); //或则textBox1.Focus();
e.Handled = false;
}
}
{
this.KeyPreview = true;
this.KeyPress += new KeyPressEventHandler(Form1_KeyPress);
} void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r')
{
SendKeys.Send("\t"); //或则textBox1.Focus();
e.Handled = true;
}
}
//给所有的textbox commobox订阅 EnterKeyDown事件foreach(Control ctrl in this.Controls)
{
if ((ctrl is TextBox) || (ctrl is ComboBox))
{
ctrl.KeyDown += new KeyEventHandler(EnterKeyDown);
}
}
private void EnterKeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
{
SendKeys.Send("{TAB}");
}
}