How can I detect changes in any control of the form in C#?
As I have many controls on one form and i need to disable a button if any of the control value in the form changes. I am in search of some built-in function/event-handler/property, and don’t want to make a customized function for that.
No, I’m not aware of any event that fires whenever any control on the form changes.
My advice would be to subscribe to each event individually (if your form has so many controls that this is actually difficult to do, then you may want to re-think your UI).
If you absolutely must subscribe to changes to all controls then you might want to consider something similar to the following:
Note that this wouldn’t work particularly well however if you dynamically add and remove controls to the form at runtime.
Also, the
TextChangedevent might not be a suitable event for some control types (e.g. TextBoxes) – in this case you will need to cast and test the control type in order to be able to subscribe to the correct event, e.g.: