假设我打开一个表单,并希望在它关闭后附加一个命令。
FormZombie FormZombie = new FormZombie();
FormZombie.Show();
FormZombie.FormClose += delegate{Utilities.DoSomethingCool()};
如何使Utilities.DoSomethingCool()触发器仅根据FormZombie中发生的情况执行?
答案 0 :(得分:8)
您可以将条件检查添加到您的代理中:
FormZombie formZombie = new FormZombie();
formZombie.Show();
formZombie.FormClose +=
delegate
{
if (formZombie.AteEnoughBrains)
Utilities.DoSomethingCool();
};