开发者

Conditional Delegate Question

开发者 https://www.devze.com 2023-01-08 19:34 出处:网络
Let\'s say I open a form and want to attach a command to it after it closes. FormZombie FormZombie = new FormZombie();

Let's say I open a form and want to attach a command to it after it closes.

FormZombie FormZombie = new FormZombie();
FormZombie.Show();
FormZombie.FormClose += delegate{Utili开发者_开发技巧ties.DoSomethingCool()};

How can I make Utilities.DoSomethingCool() trigger only executes depending on what happens in FormZombie?


You can add the conditional check into your delegate:

FormZombie formZombie = new FormZombie(); 
formZombie.Show(); 
formZombie.FormClose += 
    delegate
    {
        if (formZombie.AteEnoughBrains)
            Utilities.DoSomethingCool();
    };
0

精彩评论

暂无评论...
验证码 换一张
取 消