PDA

Click to See Complete Forum and Search --> : how do i stop creating lots of forms


sagey
Apr 14th, 2004, 04:39 AM
i have a form (form1) which has a button, which when clicked opens a new form (form2).

My problem is that after clicking form1's button to open form2, i can go back to form1 and repeatedly click the button to create multiple instances of form2.

So my question is how do limit form1 to only create one instance of form2?

Tewl
Apr 14th, 2004, 10:07 AM
have only one instead of form 2 created do not instanciate it in the button click

hellswraith
Apr 14th, 2004, 02:57 PM
http://abstractvb.com/code.asp?A=1096

Take the code from that above, and apply it to your form class code. It should do the trick.

hellswraith
Apr 14th, 2004, 03:02 PM
Sorry,

Forgot I was in the C# forum...

Here is a C# link for you:

http://www.c-sharpcorner.com/Code/2003/Jan/SingletonPattern.asp

wey97
Apr 22nd, 2004, 08:12 AM
Unless you don't want the user to get back to Form1 until Form2 is closed.

In that case just do a ShowDialog()

Form2 frm2 = new Form2();

frm2.ShowDialog();

wossname
Apr 23rd, 2004, 09:30 AM
Probably closer to this actually :)


Form2 frm2 = new Form2();

frm2.ShowDialog(Me);


or if you want a fancy one-shot...


x = (new Form2).ShowDialog(Me)