方法一, 重写 ProcessCmdKey
方法:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(keyData == Keys.Enter )
{
SendKeys.Send("{Tab}");
return true;
}
return base.ProcessCmdKey (ref msg, keyData);
}
方法二 写在窗体的KeyDown 事件中
private void frmLogin_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter )
{
SendKeys.Send("{Tab}");
}
}
注意窗体的 keypreview属性为true.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(keyData == Keys.Enter )
{
SendKeys.Send("{Tab}");
return true;
}
return base.ProcessCmdKey (ref msg, keyData);
}
方法二 写在窗体的KeyDown 事件中
private void frmLogin_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter )
{
SendKeys.Send("{Tab}");
}
}
注意窗体的 keypreview属性为true.