假设我打开一个表单,并希望在它关闭后附加一个命令.
FormZombie FormZombie = new FormZombie();
FormZombie.Show();
FormZombie.FormClose += delegate{Utilities.DoSomethingCool()};
Run Code Online (Sandbox Code Playgroud)
我怎样才能使Utilities.DoSomethingCool()触发器只执行取决于FormZombie中发生的事情?
您可以将条件检查添加到您的委托中:
FormZombie formZombie = new FormZombie();
formZombie.Show();
formZombie.FormClose +=
delegate
{
if (formZombie.AteEnoughBrains)
Utilities.DoSomethingCool();
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
92 次 |
| 最近记录: |