我有一个表格来询问一些数据。在离开输入字段(TextBox、DGV)时,调用适当的 _Validating 方法或 _CellValueChanged 方法。
如果我想结束程序,也会调用这个方法——在调用 _FormClosing 方法之前。
如何确定程序是否分支到 _FormClosing 方法?
private void txb_Validating(object sender, CancelEventArgs e)
{
doLog("Text 1");
}
private void dgv_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
doLog("Text 2");
}
private void doLog(string txt)
{
// this is first called at closing...
if( [FormClosing is active] )
{
// Do something
}
else
{
// Do someting different
}
}
private void MyForm_FormClosing(object sender, FormClosingEventArgs e)
{
// ... and this but later
// Write the Logfile
}
我如何替换 [FormClosing is active] 以获得正确的结果?
我试过了
if ( this.FormClosing== true )
所以
this.FormClosing +=new FormClosingEventHandler(MyForm_FormClosing);
所以
FormClosingEventHandler cl = new FormClosingEventHandler(MyForm_FormClosing);
但我总是走入死胡同。