日期:2014-05-18  浏览次数:20824 次

如何对右上角的关闭按钮,进行事件关联?
比如说,很多软件的窗口,在点击右上角的关闭按钮时,都会弹出一个窗口向用户提醒是否真的需要关闭程序

这样的功能怎么在C#中实现?

------解决方案--------------------
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);


private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{

}
------解决方案--------------------
在事件面板里面找到FormClosing事件,双击就会生成一个方法,里面写:

C# code
if(MessageBox.Show("确定要退出吗?","提示",MessageBoxButtons.YesNo,MessageBoxIcons.Question) != MessageBoxButtons.Yes))
 e.Cancel = true;