EventHandler with custom arguments

后端 未结 3 1791
自闭症患者
自闭症患者 2020-12-05 20:21

I\'ve been looking for an answer for about an hour on Google but I did not found exactly what I\'m looking for.

Basically, I have a static Helper class that helps pe

3条回答
  •  独厮守ぢ
    2020-12-05 20:56

    I think the simplest code would be this:

        EventHandler myEvent = (sender, e) => MyMethod(myParameter);//my delegate
    
        myButton.Click += myEvent;//suscribe
    
        private void MyMethod(MyParameterType myParameter)
        {
         //Do something 
    
         //if only one time
         myButton.Click -= myEvent;//unsuscribe
        }
    

提交回复
热议问题