What do you do to pass information between forms? Forward is straight forward (sorry) using Properties or maybe parameters in a New() or DoStuff() method, but what about sending something back when the user is done with the second form? (IE. ID of the item selected) We have used all these:
- Passed the calling form into the called form as a ref so the called form could access properties or methods on the calling form. I really don't like this because the two forms are very dependent of each other. Passing the calling form as a object only slightly improves this.
- Use Events This somewhat decouples the code, but the signatures must match on the event handler.
- Use an Public Interface I'm talking about the .NET built in one, but I suppose you could create your own. This seems like the best to me.
Now raise the bar, what if the forms are in two different DLLs? As long as the forms are not dependent on each other, I would think this wouldn't be a big step.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…