C#窗体在点击右上角(最大化,最小大那里关闭按钮)关闭按钮以后弹出MESSGBOX。进行确认的代码怎么写?
展开全部
窗体的构造函数里添加:
this.FormClosing += new FormClosingEventHandler(Form_FormClosing);
然后添加一个方法,如下:
void Form_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("退出程序?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
e.Cancel = true;
}
this.FormClosing += new FormClosingEventHandler(Form_FormClosing);
然后添加一个方法,如下:
void Form_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("退出程序?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
e.Cancel = true;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询