Windows Form in c# ?

  • Thread starter Thread starter WJ
  • Start date Start date
W

WJ

I am using SDI model. How do I check if a Form is already exists in a c#
Windows Application so that I do not have to create another instance,
istead, just doing the "formName.show()" ?

Thanks

John
 
WJ said:
I am using SDI model. How do I check if a Form is already exists in a c#
Windows Application so that I do not have to create another instance,
istead, just doing the "formName.show()" ?

Stringe question... The main SDI Window will be there for the lifetime of
the application. Any additional Window will be created by you and you will
have full control over it. If you feel that disposal and recreation is
expensive, just hang on to your reference.

Martin.
 
I am using SDI model. How do I check if a Form is already exists in a c#
Windows Application so that I do not have to create another instance,
istead, just doing the "formName.show()" ?

Thanks

John

What about:

if (form == null)
form = new Form();
form.Show();
 
Martin Maat said:
Stringe question... The main SDI Window will be there for the lifetime of
the application. Any additional Window will be created by you and you will
have full control over it. If you feel that disposal and recreation is
expensive, just hang on to your reference.
Not strange at all. Sometimes you do not do Dispose() but the object
disappears on you (in a blue moon) anyway, other times you would forget to
call Dispose() and endup filling up all precious RAM. As a result, it is
always a good practice to make sure the thing exists before you reference
it. Otherwise, create it.

John
 
Not strange at all. Sometimes you do not do Dispose() but the object
disappears on you (in a blue moon) anyway.

No, if this were a possibility it would be pointless to write any code. You
should find why this is happening and fix your code.

It seems like you are keeping weak references in some way and then unrightly
expect the object to remain.

Martin.
 
Back
Top