Hello,

I am creating two forms Form1 and Form2 in C#. On Form1 there's a button to create more than one instance of Form2 based on a number provided by user. Here's the code to create Form2 instances:

for(int i=0; i < numOfCopies ; i++)
{
   new Form2.show();
}

The problem is when there are more than one instances of Form2, changing values of any control on one form changes the value of the control in another form as well. How can the data be separated for these forms?

Thanks.

Recommended Answers

All 2 Replies

You did get this new Form2.show(); through the compiler???

Anyway, this is how it should be done

for (int i = 0; i < numOfCopies; i++)
{
  Form2 newForm;

  newForm = new Form2();
  newForm.Show();
}

Sorry I posted incorrect code. I actually did it the way you've suggested and got the error mentioned earlier.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.