Form Closing Problem and MessageBox Independence [modified]
-
Maybe I have to use a form to do that rather than using a messagebox. It seems like a message box depends on the form it is being called. I do have a form where I have a line of code to call a dialog. From that dialog, I open another form. When the user click ok, I want the first form to close, however it does not close. here is what I am talking about for example, assume that my form is form 3, inside my form 3, I have a dialog to open form two. When the user clicks ok, form 2 will open where form 3 will close, however form 3 never closes inside form 3 I have if (dialogresponse == dialogresult.ok) form3.activeform.close(); then create an open form 2 The way to look at it, form 3 only close after form 2 open and close it does not work, it seems like I have to do that in another form. I don't want fo have a form for that only. Maybe I am missing something. -- modified at 20:02 Thursday 14th December, 2006
-
Maybe I have to use a form to do that rather than using a messagebox. It seems like a message box depends on the form it is being called. I do have a form where I have a line of code to call a dialog. From that dialog, I open another form. When the user click ok, I want the first form to close, however it does not close. here is what I am talking about for example, assume that my form is form 3, inside my form 3, I have a dialog to open form two. When the user clicks ok, form 2 will open where form 3 will close, however form 3 never closes inside form 3 I have if (dialogresponse == dialogresult.ok) form3.activeform.close(); then create an open form 2 The way to look at it, form 3 only close after form 2 open and close it does not work, it seems like I have to do that in another form. I don't want fo have a form for that only. Maybe I am missing something. -- modified at 20:02 Thursday 14th December, 2006
-
Hi, are you using MDI interface style. if yes then try using ActiveMdiChild property. if not then see if your ActiveForm is not returning null reference. further if you are running this code inside form3, can you not simply call this.close(). Regards.
I am not using MDI, my application is simply single document or single form. Also I already tried this.close but it does not work by the way this is the simple code
DialogResult myMessage; messageResponse = MessageBox.Show("message", "title", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (myMessage== DialogResult.OK) { Form2 form2= new Form2(); form2.ShowDialog(); Form3.ActiveForm.Close();//this does not work here, it does not matter what form that I use }