Hello,
Quote:
The Form1 is used as a Mdi container with WeifenLuo.WinFormsUI.Docking, so I am showing there the Form2 and Form3.
You are doing it wrong. You are creating both Form2 and Form3 instances in Form1 (MDI). Then in Form2 you are creating another instance of Form3. It's completely wrong.
I suppose that Form3 is just form with progress bar control only to show operation progress to the user and there is no other use of this form.
1. In Form1 you need to create and show Form2 only:
var form2 = new Form2();
form2.Show();
2. Then create Form3 inside Form2:
private Form3 myOtherForm = new Form3();
public doWork()
{
this.myOtherForm.Show();
foreach (Element zenVar in lstAlarms)
{
this.myOtherForm.IncrementProgessBar = 1;
}
this.myOtherForm.Hide();
}
Second solution is to create Form2 and Form3 in Form1 and then pass reference to created Form3 instance directly to Form2 via constructor.
But in my opinion both solutions are a bad design. For simple, home project with 4-5 forms it can be 'acceptable' but for medium/large size projects you should consider using some Design Patterns. For instance:
1. Model-View-Presenter - which can help you separate your app layers
2. Create some kind AppHost/Shell to manage object communication, especially when you're dealing with many forms and want to pass data between them.
3. And most important use S.O.L.I.D. programming :)
You can find many articles about SOLID and Design Patterns here on CP. Good Luck.
I hope that help you.