I'm working with a bit of code that is structured thusly:
Form A has user controls B and G within it. User control B has User control D within it, and user control D has a "refresh" method. User control G has user control F within it, and user control F needs to call the "refresh" method in D.
1) Short of restructuring the code (It's legacy code, so it's off the table as an option), are delegates the best way to go about handling this issue? If not, do you have another suggestion?
2) I have no experience with delegate functions -- is there a good primer or example that I could use to adapt to my code to achieve the desired functionality?
First, F should not know anything about D and its refresh function. Add event to F, which is raised when necessary. If form A knows about F, subsctibe to this event from A. If not, make similar event in G, and subscribe to it in A. In A event handler, call Refresh directly, or call B method, which calls D.refresh.
It looks like my answer is even less readable than your question :) It should look like this:
F raises event -> G handles F's event and raises event -> A handles G's event and calls B method -> B method calls D.refresh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With