嘿! 我不是想在这里推动我的运气,但我有另一个c#问题.我尝试过使用谷歌发现的所有可能事件.这是代码:
private void Form1_OnClose() { MessageBox.Show("I was closed -2"); } private void Form1_Exit(object sender, EventArgs evArgs) { MessageBox.Show("I was closed -1"); } private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { MessageBox.Show("I was closed 0"); } private void Form1_Closed(object sender, EventArgs e) { MessageBox.Show("I was closed 1"); } private void Form1_FormClosed(Object sender, FormClosedEventArgs e) { MessageBox.Show("I was closed 2"); }
当我执行Alt + f4或单击X按钮时,其中没有一个会触发任何内容.我在这做错了什么?
您可能缺少实际的订阅代码,这是以下几点:
this.Closing += Form1_Closing;
相反,尝试重写OnXXX方法 - 这是做事的首选方式.