Prevent from opening two instance of child form

sethindeed

Centurion
Joined
Dec 31, 1969
Messages
118
Location
Montreal Canada
I haven't been able to retrieve this information when searching on the forum...
My question is simple :

How can I prevent my program of opening two instance of the same child form ?

thx
 
could you not use something like a boolean?
maybe Dim FrmLoaded as Boolean
then on start up the boolean = False and when you load the first instance of the child form the boolean = True ,
then if the boolean = true tell it not to be able to load a childform ( ie: if frmLoaded = True then exit sub , else frmChild = new form2 , frmChild.Show blabla )
 
My suggestion would be to expand on dynamic_sysop's suggestion by making that boolean variable a static ("shared" in vb.net) member of the form class. Then in the form's constructor you could set it to true, and check it before creating a new instance of the class.
 
Well, there is with a MDI form, but I don't think there is with a regular application aside from using System.Diagnostics.Process.GetProcessesByName() and GetProcessById() methods.
 
The Forms collection from VB6 is no longer available. As wyrd mentioned, an MDI form knows about it's children, but looping through them all is not the .NET way - I'd go with divil's and dynamic_sysop's suggestions.

-Nerseus
 
i always like the blabla explanation lol.
the boolean has been a god send in vb6 for me so i carried it over and have used it for various instances in .net already.
anyway glad to have finally been of assistance to someone on here instead of me asking a question.
 
Back
Top