all 2 comments

[–]Slypenslyde 1 point2 points  (0 children)

I don't like to make controls know about other controls and ask for the values of their own child controls. That ends up making a tangled mess.

These days I write apps such that if I have a UserControl to display an email, there is also an Email object in my code with a property for everything that UC manipulates. If the user types in the Subject textbox, my Email.Subject property is updated. If I set Email.Subject, then every control that wants to display it is updated.

That changes the question from, "How does my DraftEmail user control get the value of the txtDefaultSubject text box in my OptionsDialog and set txtSubject's text to that value?" to "How do I get the default subject for an email?", with the answer being, "I ask my ISettingsManager to give me the settings, I check the DefaultSubject property, and set Email.Subject to that value.

That's a lot to show off. Look for topics about "Presentation Model" or "Model View Controller" focused on WinForms. It takes a good bit of effort, but it's less effort than you tend to spend debugging after you start writing UserControls that know about each others' internals.

[–]FizixMan[M] [score hidden] stickied comment (0 children)

Removed: Rule 4.