Phillip Smilski

Phillip Smilski

  • 1.5k
  • 229
  • 923

Multiple instances of the same form without variable conflict?

Apr 26 2024 11:00 PM

Is it possible to open the same form multiple times and not have variable conflicts? I have a program controlling 4 different spectrum analyzers and I want to use the same form so I only update changes once. The issue I am having is the labs I am writing this for use different spectrum analyzers so the XML file has setting for each that differ. I noticed that I am actually using the variable settings from the last form that was opened. I fixed this by copy the form and renaming it 4 times, but this seems like I am going to miss changes throughout. The main form called this from buttons.

Spec_AN_form SA_form1 = new Spec_AN_form();
SA_form1.Show(); 

Spec_AN_form SA_form2 = new Spec_AN_form();
SA_form2.Show(); 

Spec_AN_form SA_form3 = new Spec_AN_form();
SA_form3.Show(); 

Spec_AN_form SA_form4 = new Spec_AN_form();
SA_form4.Show(); 

This did not work correctly so now I have 4 duplicate forms and open each. i.e. Spec_AN_form1 SA_form1 = new Spec_AN_form1(); This does work but now I have to maintain 4 sets of duplicate code. There has to be a better way.


Answers (4)