You create a private instance of Form1 when Form1 is created, so this is kind of an infinite loop:
Somewhere in your code, you create your first instance of Form1. When this instance is created, it creates a new instance of Form1. This instance also creates an instance of Form1, and again, and again, etc.
So, when an instance is created, all variables are initialized and when you declare them as follows: Form1 f1 = new Form1() this will automatically activate a new instance of the form.
I suggest that you do not have a new instance of Form1 inside Form1, but if you really need to create a method to instantiate:
Change Form1 f1 = new Form1(); on Form1 f1; . And create a method:
public void InstantiateNewForm1Instance() { f1 = new Form1(); }
But: DO NOT CALL THIS METHOD IN THE DESIGNER! Or you will have the same problem :-)
Zenuka
source share