private void ctrl_KeyPress(object sender, KeyPressEventArgs e){
if( e.KeyChar == (char)13 )
{
// 发送“TAB”键,切换到下一控件。
SendKeys.Send( "{TAB}" );
// 指示 KeyPress 事件已处理,去掉 Windows 缺省的叮当声。
e.Handled = true;
}
}
本文介绍了一个简单的C#方法,用于在文本框或其他输入控件中拦截用户的回车键输入,并通过SendKeys API模拟按下Tab键,实现焦点跳转到下一个控件的功能。该方法还包含了对KeyPress事件的处理,避免了默认的声音反馈。
private void ctrl_KeyPress(object sender, KeyPressEventArgs e)
被折叠的 条评论
为什么被折叠?