在WinForm输入控件中用回车键代替TAB键
1、请先设置窗体的keyPreView属性为True,确认控件的键盘事件向窗体注册;
2、在窗体的KeyPress事件中编写如下代码:
2、在窗体的KeyPress事件中编写如下代码:
1 private void Form1_KeyPress(object sender, KeyPressEventArgs e)
2 {
3 if (e.KeyChar == (char)13)
4 {
5 e.Handled = true;
6 SendKeys.Send("{TAB}");
7 }
8 }
2 {
3 if (e.KeyChar == (char)13)
4 {
5 e.Handled = true;
6 SendKeys.Send("{TAB}");
7 }
8 }