Embarrassed - Simple Form Question
-
Hi I have main form with a button, which when pressed, displays a second form. I don't want this form modal, so I use Show(). But, I only ever want one instance of this form. My confusion, and I am a real C# / .NET newbie, is when / where / how this is created / destroyed. Here's what I am doing...pseudoish MainForm.OnClickEvent(...) { if secondform == null secondform = new form(data_for_form_listbox) secondform.show() } secondform.onCloseBUtton(....) { Close(); //or should this be hide();//I want the C++ equiv of EndDialog / CloseWindow which will actually delete the instance } On the 'secondform' I have a close button, which, calls - 'Close()'. Does that destroy the window? I want it destroyed so my OnClickEvent will create a new instance, so my second form can refresh its data (via the ctor). I don't need code samples just a basic step by step of where I should create the second form / how I close it, (via teh second form), and should I destroy / recreate etc. Does this make sense? Regards :rose: Angel :rose: ********************************************* The sooner you fall behind, the longer you have to catch up.
-
Hi I have main form with a button, which when pressed, displays a second form. I don't want this form modal, so I use Show(). But, I only ever want one instance of this form. My confusion, and I am a real C# / .NET newbie, is when / where / how this is created / destroyed. Here's what I am doing...pseudoish MainForm.OnClickEvent(...) { if secondform == null secondform = new form(data_for_form_listbox) secondform.show() } secondform.onCloseBUtton(....) { Close(); //or should this be hide();//I want the C++ equiv of EndDialog / CloseWindow which will actually delete the instance } On the 'secondform' I have a close button, which, calls - 'Close()'. Does that destroy the window? I want it destroyed so my OnClickEvent will create a new instance, so my second form can refresh its data (via the ctor). I don't need code samples just a basic step by step of where I should create the second form / how I close it, (via teh second form), and should I destroy / recreate etc. Does this make sense? Regards :rose: Angel :rose: ********************************************* The sooner you fall behind, the longer you have to catch up.
-
Hi I have main form with a button, which when pressed, displays a second form. I don't want this form modal, so I use Show(). But, I only ever want one instance of this form. My confusion, and I am a real C# / .NET newbie, is when / where / how this is created / destroyed. Here's what I am doing...pseudoish MainForm.OnClickEvent(...) { if secondform == null secondform = new form(data_for_form_listbox) secondform.show() } secondform.onCloseBUtton(....) { Close(); //or should this be hide();//I want the C++ equiv of EndDialog / CloseWindow which will actually delete the instance } On the 'secondform' I have a close button, which, calls - 'Close()'. Does that destroy the window? I want it destroyed so my OnClickEvent will create a new instance, so my second form can refresh its data (via the ctor). I don't need code samples just a basic step by step of where I should create the second form / how I close it, (via teh second form), and should I destroy / recreate etc. Does this make sense? Regards :rose: Angel :rose: ********************************************* The sooner you fall behind, the longer you have to catch up.
Angel1058 wrote:
'Close()'. Does that destroy the window?
If you mean will
secondform
be a null pointer after it's called, then no.Close()
disposes the form and it's contents, and destroys it's window handle, but comparing secondform to null (like you're doing in yourOnClickEvent()
method) will return false. You can use theIsDisposed
property of the Form to check to see if the form has been disposed, and that should work (but you'd have to check if it's null first)...if ( secondform == null || secondform.IsDisposed )
secondform = new MyForm(data_for_form_listbox)Hope that helps :)
“Accept that some days you are the pigeon, and some days you are the statue” -- David Brent Cheers, Will H
-
Angel1058 wrote:
'Close()'. Does that destroy the window?
If you mean will
secondform
be a null pointer after it's called, then no.Close()
disposes the form and it's contents, and destroys it's window handle, but comparing secondform to null (like you're doing in yourOnClickEvent()
method) will return false. You can use theIsDisposed
property of the Form to check to see if the form has been disposed, and that should work (but you'd have to check if it's null first)...if ( secondform == null || secondform.IsDisposed )
secondform = new MyForm(data_for_form_listbox)Hope that helps :)
“Accept that some days you are the pigeon, and some days you are the statue” -- David Brent Cheers, Will H
secondform.IsDisposed
That's what I was missing - many thanks. Amazing, I've used MFC/VC++ for years and years and yet couldn't even successfully close and reopen a form in C#....doh. Thanks again. Regards :rose: Angel :rose: ********************************************* The sooner you fall behind, the longer you have to catch up.