日期:2014-05-19  浏览次数:20974 次

窗体关闭问题??
我已经在FormClosing中写好关闭的相关判断语句,但现在我想用该窗体上的一个按钮来直接调用FormClosing所实现的功能   怎么操作呢?FormClosing中的代码如下:

                private   void   Test_FormClosing(object   sender,   FormClosingEventArgs   e)
                {

                        DialogResult   dr;
                        dr   =   MessageBox.Show( "是否真的要关闭窗体? ",   "提示信息   ",   MessageBoxButtons.OKCancel,   MessageBoxIcon.Information,   MessageBoxDefaultButton.Button2);
                        if   (dr   ==   DialogResult.Cancel)
                        {
                                e.Cancel   =   true;
                             
                        }
                }


------解决方案--------------------
DialogResult dr;
dr = MessageBox.Show( "是否真的要关闭窗体? ", "提示信息 ", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
if (dr == DialogResult.Cancel)
{
return;

}
this.close();

------解决方案--------------------
这样就自动调用FormClosing事件了

private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}