WinForms: temporarily disable an event handler

后端 未结 3 1047
难免孤独
难免孤独 2020-12-10 10:22

How can I disable an event handler temporarily in WinForms?

3条回答
  •  醉酒成梦
    2020-12-10 11:19

    Disable from what perspective? If you want to remove a method that's in your scope from the list of delegates on the handler, you can just do..

    object.Event -= new EventHandlerType(your_Method);
    

    This will remove that method from the list of delegates, and you can reattach it later with

    object.Event += new EventHandlerType(your_Method);
    

提交回复
热议问题