How to remove all event handlers from an event

后端 未结 18 1605
再見小時候
再見小時候 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:56

    Well, here there's another solution to remove an asociated event (if you already have a method for handling the events for the control):

    EventDescriptor ed = TypeDescriptor.GetEvents(this.button1).Find("MouseDown",true);            
    Delegate delegate = Delegate.CreateDelegate(typeof(EventHandler), this, "button1_MouseDownClicked");
    if(ed!=null) 
        ed.RemoveEventHandler(this.button1, delegate);
    

提交回复
热议问题