在窗体的closing事件中:
void frm_closing(object sender, FormClosingEventArgs e)
{
if(MessageBox.Show("确定退出吗?","我的程序",MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2)==DialogResult.OK)
{
e.Cancel=false;
}
else
{
e.Cancel=true;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("程序即将关闭...", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
this.canClose = true;
this.Close();
}
else
{
e.Cancel = true;
}
}