博客园  :: 首页  :: 管理

如何在关闭窗体时显示确定对话框?

Posted on 2005-11-30 16:10  Paker Liu  阅读(539)  评论(0编辑  收藏  举报
1. 添加引用:
using System.ComponentModel;

2.添加窗体Closing事件
private void Form1_Closing( object sender, CancelEventArgs e )
{
string text = "确定退出程序?";
string caption = "关闭程序";
if (MessageBox.Show( text, caption, MessageBoxButtons.YesNo) == DialogResult.No )
e.Cancel = true;
}