Check if Windows Form is already loaded
-
Hi guys, I guess it's a pretty easy question for you. How do you check if a Windows Form (object) is already loaded in C#? Thanks!
-
Hi guys, I guess it's a pretty easy question for you. How do you check if a Windows Form (object) is already loaded in C#? Thanks!
What do you mean? Are you talking about an MDI Child form? In any case, your code should be written to track this information as it happens. Your code is the only thing that is going to load and instantiate the form so tracking this is pretty easy... RageInTheMachine9532
-
What do you mean? Are you talking about an MDI Child form? In any case, your code should be written to track this information as it happens. Your code is the only thing that is going to load and instantiate the form so tracking this is pretty easy... RageInTheMachine9532
-
Yes, I mean the MDI child form, because it can be loaded multiple times. We just want to have one form at a time.
Great! When your app creates the child form, just set a global flag that says the form has been created. When you go to create the child form, just check the flag first. Done! RageInTheMachine9532
-
Great! When your app creates the child form, just set a global flag that says the form has been created. When you go to create the child form, just check the flag first. Done! RageInTheMachine9532
-
Can I do this:
private someForm form; if (form == null) form = new someForm();
Also, is form = null when disposed? How do I know if a form is disposed? Thank!Actually you do both, call the Dispose() method and set the variable to null. Dispose will tell the instance to release the resources it holds while setting the variable to null will release the reference to that instance. Calling Dispose will release the resources when YOU want it to and not when the garbage collector gets around to calling Dispose for you. When you set your variable to null, the reference to that instance is dropped and, since you already called Dispose, the garbage collector only has to free the memory that the instance occupied. When you do both Dispose and null, you release resources and memory much quicker than if you waited for the GC to get around to it. RageInTheMachine9532