Determine if an event has been attached to yet

前端 未结 4 1169
悲哀的现实
悲哀的现实 2021-01-12 07:12

I have two objects - one that contains some code with will fire an event, and one that contains the handler for that event. I can\'t \"AddHandler\" in the Load of the first

4条回答
  •  天命终不由人
    2021-01-12 07:19

    If you just want to know whether any handler has been attached, you should be able to check whether the event is null.

    if (MyButton.Click == null)
    {
        MyButton.Click += myEventHandler;
    }
    

    (I'll let you translate that into VB)

提交回复
热议问题