1.监听窗体关闭事件(rslr_main为窗体名)
public rslr_main() { InitializeComponent(); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(Form_Closing); } private void Form_Closing(object sender, FormClosingEventArgs e) { ExcelExit(); Owner.Show(); }
2.按键监听
//下一件快捷键 private void rssm_main_KeyDown(object sender, KeyEventArgs e) { if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D) //"Ctrl + D"触发 { //MessageBox.Show("快捷键"); } }
要把窗体的KeyPreview设置为true才有效
还要在**.Designer.cs里边加入
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.rssm_main_KeyDown);
这样就可以监听到了