C# – Interacting with User Controls through Events

cencapsulationeventsuser-controls

I've browsed through the questions on the site, but haven't found a decent answer yet.

My problem is that my main form class is cluttered due to all the events and methods.

I decided to break the form into user controls. Unfortunately I am having trouble accessing information from other User controls.

For example I have a user control that prints some information. But some of that information is in another User Control. How would I retrieve that data?

One solution I read was to pass a delegate to the Print User control. The delegate would contain a method from the Information User Control that returned the data from the control. So whenever the print event is called I would call that function.

The other solution I had was to attach an event to the information User Control. Whenever the information in the User Control changed, I would update my print variables.

Best Answer

Why do you need to use events for this at all? If control X needs information from control Y, then pass control Y into control X's constructor.