Is there a clean way to remove a control and it's associated event handlers?
-
I haven't found a clean way to remove a control (say a button) and any associated event handlers. What I do now is delete the control from the form, then find the event handlers in the code, and delete them. When I recompile, I get errors due to the deleted event handler code, and have to perform more surgery to clean them up. I'm new to dotNet, so be kind... There must be an easier way!
-
I haven't found a clean way to remove a control (say a button) and any associated event handlers. What I do now is delete the control from the form, then find the event handlers in the code, and delete them. When I recompile, I get errors due to the deleted event handler code, and have to perform more surgery to clean them up. I'm new to dotNet, so be kind... There must be an easier way!
If you're talking at design time, then I have run into the same "problem"... removing a control from the design view removes the declaration and instanciation of that control from the IDE-generated code but not anything related like the even handlers.. ..I usually do that by hand. If you're talking at run time, I think that removing the control from the Controls collection of the form should do the trick (the handlers are still in the compiled code but they will not get called...) HTH, Olorin
-
I haven't found a clean way to remove a control (say a button) and any associated event handlers. What I do now is delete the control from the form, then find the event handlers in the code, and delete them. When I recompile, I get errors due to the deleted event handler code, and have to perform more surgery to clean them up. I'm new to dotNet, so be kind... There must be an easier way!
Any handlers added by using the IDE will get removed when you delete the control. If you add handlers by hand then you'll have to remove them by hand as well. James "I despise the city and much prefer being where a traffic jam means a line-up at McDonald's" Me when telling a friend why I wouldn't want to live with him
-
I haven't found a clean way to remove a control (say a button) and any associated event handlers. What I do now is delete the control from the form, then find the event handlers in the code, and delete them. When I recompile, I get errors due to the deleted event handler code, and have to perform more surgery to clean them up. I'm new to dotNet, so be kind... There must be an easier way!
-
If you're talking at design time, then I have run into the same "problem"... removing a control from the design view removes the declaration and instanciation of that control from the IDE-generated code but not anything related like the even handlers.. ..I usually do that by hand. If you're talking at run time, I think that removing the control from the Controls collection of the form should do the trick (the handlers are still in the compiled code but they will not get called...) HTH, Olorin
Sorry, I was referencing design time. The functionality you reference is what I have seen. It just seems odd that you can't delete the event handlers in one fell swoop. Oh well. Thanks for your reply.
-
Any handlers added by using the IDE will get removed when you delete the control. If you add handlers by hand then you'll have to remove them by hand as well. James "I despise the city and much prefer being where a traffic jam means a line-up at McDonald's" Me when telling a friend why I wouldn't want to live with him
What I see is the declaration and instantiation of a control (say a button) is removed when you delete the button, but not any associated event handlers, not even those created with the IDE.