Synchronizing objects with GUI controls

Every time I change some values ​​in form elements, I need to set a property of the object or vice versa. Rather than writing some methods for each control, I want a generic solution for GUI controls. I am not using WPF, only C # 3.0.

Any suggestions?

Thanks.

+2


a source to share


2 answers


All controls expose events to signal that their value has changed. You can subscribe to it and change another control value.



0


a source


You can make an object a field in your form. When the corresponding event is fired from the control, invoke the appropriate operation on the object.



Also, you have a Presenter / Controller object that saves your form as a field. It can take it as a parameter in the constructor. This host can then subscribe to your respective events and act accordingly. You can go a step further with this and extract the interface from your form and program to this in a presenter, and this will help testing. Have a look at the MVP pattern.

0


a source







All Articles