// 重写以下方法
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if(msg.WParam.ToInt32() == (int) Keys.Enter)
{
SendKeys.Send("{Tab}");
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
// 也可处理窗体的KeyDown事件
// 注:须先将窗体的keypreview属性改为True
private void Login_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode==Keys.Enter )
{
this.SelectNextControl(this.ActiveControl,true,false,false,true);
}
else if(e.KeyCode==Keys.Left )
{
this.SelectNextControl(this.ActiveControl,false,true,true,false);
}
else if(e.KeyCode==Keys.Up )
{
this.SelectNextControl(this.ActiveControl,false,true,true,false);
}
else if (e.KeyCode==Keys.Right )
{
this.SelectNextControl(this.ActiveControl,true,true,true,false);
}
else if(e.KeyCode==Keys.Down )
{
this.SelectNextControl(this.ActiveControl,true,true,true,false);
}
}