C
Charles Law
I have a form on which user controls are placed at runtime. When a control
is added to the form a handler is added for an event that a high-level
object raises, which must be handled by the new control. When I close the
form I am expecting that the control ceases to be.
However, if my object raises the event after the form has been closed, I
find that there is still a user control object that handles it. Clearly the
user control has not ceased to be after all.
What is the technique for destroying the user control so that it is no
longer around to handle my object's events?
I have tried calling Dispose on the user control but this does not help. I
do not want to have to remove the event handler manually (in code) unless
there is an easy way to remove all handlers in one fell swoop. In reality, I
have many different controls, any or all of which could be added to the form
at runtime, and which can individually handle a large number of events.
Coding to remove all the events manually would be a maintenance nightmare.
TIA
Charles
is added to the form a handler is added for an event that a high-level
object raises, which must be handled by the new control. When I close the
form I am expecting that the control ceases to be.
However, if my object raises the event after the form has been closed, I
find that there is still a user control object that handles it. Clearly the
user control has not ceased to be after all.
What is the technique for destroying the user control so that it is no
longer around to handle my object's events?
I have tried calling Dispose on the user control but this does not help. I
do not want to have to remove the event handler manually (in code) unless
there is an easy way to remove all handlers in one fell swoop. In reality, I
have many different controls, any or all of which could be added to the form
at runtime, and which can individually handle a large number of events.
Coding to remove all the events manually would be a maintenance nightmare.
TIA
Charles