I have a windows form app, and a class which is called Game.
Let’s say Game class has an attribute counter, and i do some calculations and change counter in that class. So i want to return a text to the form whenever counter changes, and then assign it to a label on the form.
Can i do it with an event handler that returns type string ? Since i have to listen it and return something whenever something happens.
Thanks in advance.
Yes you can :p
A proper way of doing this is as follow (INotifyPropertyChanged will simply tell you what property has changed and doesn’t return the actual value, but is also a good way to go):
Hopefully, I didn’t make any syntax mistake as I coded this by head 🙂 But you get the idea.
You can register your form with the even and listen to it as you would do with any control.