在WinForm中设置要使用组合键的窗体的KeyPreview(向窗体注册键盘事件)属性为True;
1 private void Form_KeyDown(object sender, KeyEventArgs e) 2 { 3 if (e.KeyCode == Keys.Escape) 4 { 5 btnCancel.PerformClick();//第1种 6 //btnCancel_Click(sender, e);第2种 7 } 8 if (e.KeyCode == Keys.A&&e.Control)//Ctrl+*..... 9 { 10 //第3种 11 e.Handle=True;//表示已经处理过KeyPress事件 12 btnAdd_Click(sender, e); 13 } 14 /*if (e.Control) 15 { 16 switch (e.KeyCode) 17 { 18 case Keys.A: 19 btnAdd.PerformClick(); 20 break; 21 case Keys.S: 22 btnSave.PerformClick(); 23 break; 24 case Keys.D: 25 btnDetele.PerformClick(); 26 break; 27 case Keys.P: 28 btnPrint.PerformClick(); 29 break; 30 default: 31 break; 32 } 33 e.Handled = true; 34 }*/ 35 }