You can scroll through all the controls, but this should be recursive because the control may contain controls, for example. (for brevity, there are no null checks):
private void IterateOverControls( Control parent ) { ProcessControl( parent ); foreach( Control control in parent.Controls ) IterateOverControls( control ); }
In ProcessControl you can connect event handlers to handle OnEnter (to save state) and OnLeave (to check the current state for a saved state). When disposing, you need to unhook all event handlers. In addition, the code for saving the verification status must change for different types of control, for example. TextBox will be a Text property, but the switch will be an index, etc. Obviously, this will be simplified if you can compare the state of the form with the base state of the data store, in which case you can simply do a comparison for each OnLeave event.
You might also wonder if you need to track real changes. For example, I have 2 switches: A and B. I check B (change), so the exit button or any other Enabled property changes. Then I press A (returning to the initial state). Do you need to return the button at this moment?
That is why you should look at the model controller approach :)
source share