Best practice when you need two user controls (winforms) to communicate

前端 未结 3 698
深忆病人
深忆病人 2021-02-10 12:28

Extended problem

I would like to add a new problem in addition to the original problem specified below. One of the user controls in the application cont

3条回答
  •  情书的邮戳
    2021-02-10 13:24

    The two user controls should not have any knowledge of each other. If you want to always deal with them as a pair, consider creating a third user control to house them.

    Should the form wait for an Event from A, and then start the operation on B?

    Yes, this is the only good way to handle this.

    The extended (bonus?) problem is a bit trickier. I would handle this by having the form pass the user control a delegate to a method on the other user control to retrieve the data. The user control can then invoke the delegate method to call the method on the other control without having any knowledge of its implementation.

提交回复
热议问题