How to remove all event handlers from an event

后端 未结 18 1572
再見小時候
再見小時候 2020-11-22 01:20

To create a new event handler on a control you can do this

c.Click += new EventHandler(mainFormButton_Click);

or this

c.Cli         


        
18条回答
  •  北海茫月
    2020-11-22 01:52

    You guys are making this WAY too hard on yourselves. It's this easy:

    void OnFormClosing(object sender, FormClosingEventArgs e)
    {
        foreach(Delegate d in FindClicked.GetInvocationList())
        {
            FindClicked -= (FindClickedHandler)d;
        }
    }
    

提交回复
热议问题