C# winform窗体关闭按钮

添加form的FormClosing事件 

         /// <summary>
         /// 主窗口自带的关闭按钮
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="e"></param>
          private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
         {
             DialogResult result;
             result = MessageBox.Show("确定退出吗?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
             if (result == DialogResult.OK)
             {
                 Application.ExitThread();
             }
             else
             {
                 e.Cancel = true;
             }
         }

posted @ 2012-12-23 17:07  Entropy_lxl  阅读(739)  评论(0编辑  收藏  举报