2

Providing the particular field as an argument in the constructor of the second form? Or making the field as a public static property and then access it from the second form? Or are these completely different concepts and I am mixing up things? The forms do not share any parent child (MDI) relationship.

Candy
  • 133
  • 1
  • 10
  • are you automatically updating the second form field or a trigger like a button trigger will update the seconds' form field? – Talkhak1313 Jan 18 '23 at 07:41
  • @Satir1313 on triggering. – Candy Jan 18 '23 at 09:54
  • The question about communication between forms have may good answers in SO, like this one [Interaction between forms — How to change a control of a form from another form?](https://stackoverflow.com/q/38768737/3110834). But if you are looking for a special advise for a special case, you need to share more context, about their life time, and their instantiation, and their scope, and the data tht you want to pass, and when you want to pass data. The question in the current format is opinion based. – Reza Aghaei Jan 18 '23 at 19:36

2 Answers2

3

Have a class that controls both forms. Let it subscribe to an event in the first form that triggers when the field changes, and then let the class update the second form with the changed value.

In that way, both forms are independent of each other. That's good since it produces cleaner code with fewer reasons for failure.

jgauffin
  • 99,844
  • 45
  • 235
  • 372
1

One approach will be the one that @jgauffin mentioned. To keep forms decoupled and reusable you can pass the object in the constructor of the second form. then INotifyPropertyChanged can be used to update the other form(s) if required. INotifyPropertyChanged Interface will help you to understand how it works and sample code to use.

Talkhak1313
  • 301
  • 2
  • 11