FormClosing事件问题 [英] FormClosing event question

查看:91
本文介绍了FormClosing事件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在复制表单时有一些代码.在此表单中是一个btnOK,它先生成内容,然后关闭表单.用户按下btnOK时如何关闭以下代码(如果使用)

Hello everybody i have some code when form is cloasing. In this form is a btnOK which is make something and then closing form. how to switch off following code when user press the btnOK (in if)

private void Sell_FormClosing(object sender, FormClosingEventArgs e)
{

    if (dgvProducts.Rows != null )
    {
        if (MessageBox.Show("do u really want to close?", "attention", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
        {
            e.Cancel = false;
        }
        else
        {
            e.Cancel = true;
        }
    }

}

推荐答案

private void Sell_FormClosing(object sender, FormClosingEventArgs e)
{
    if (this.DialogResult == false)
    {
        if (dgvProducts.Rows != null )
        {
            e.Cancel = (MessageBox.Show("do u really want to close?", "attention", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes);
        }
    }
}


这篇关于FormClosing事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆