标签:
一、PreviewKeyDown、KeyDown、KeyPress、KeyUp相关:http://blog.csdn.net/jiankunking/article/details/20611383
需要焦点在控件上才能监听按键。
二、以下代码是重写事件来监听左右键,取消点击回车在datagridview中选中下一行。
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.Enter) { if (tabControl1.SelectedIndex == 0) showCountP(); else if (tabControl1.SelectedIndex == 1) showCountI(); return base.ProcessDialogKey(keyData); } if (keyData == Keys.Left) { if (tabControl1.SelectedIndex == 0) tabControl1.SelectedTab = tabPage2; else if (tabControl1.SelectedIndex == 1) tabControl1.SelectedTab = tabPage1; return true; } if (keyData == Keys.Right) { if (tabControl1.SelectedIndex == 0) tabControl1.SelectedTab = tabPage2; else if (tabControl1.SelectedIndex == 1) tabControl1.SelectedTab = tabPage1; return true; } else { return false; } }
标签:
原文地址:http://www.cnblogs.com/qixinjian/p/5720971.html