Kalint Posted September 27, 2013 Share Posted September 27, 2013 private void ReOpen() { Hide(); var reopen = new FrmPlaceItem(); reopen.ShowDialog(); Dispose(); } Soooo.... when I call this method, is it actually closing the current form and reopening a new one; or is the previous form still hidden :/ Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted September 27, 2013 Veteran Share Posted September 27, 2013 Hiding the form does not close it. To close the form, call Close() (you don't need to call Dispose()). ShowDialog() is a blocking call that doesn't return until the dialog is closed. If you call Close() after calling ShowDialog() on the new form, the current form won't close until the dialog is closed. Avoid using ShowDialog() unless you actually want a modal window. It doesn't make any sense to try to show a modal window after closing the parent window (hence why your code can't work). Not sure what you're trying to achieve... Link to comment Share on other sites More sharing options...
0 Kalint Posted September 27, 2013 Author Share Posted September 27, 2013 Hiding the form does not close it. To close the form, call Close() (you don't need to call Dispose()). ShowDialog() is a blocking call that doesn't return until the dialog is closed. If you call Close() after calling ShowDialog() on the new form, the current form won't close until the dialog is closed. Avoid using ShowDialog() unless you actually want a modal window. It doesn't make any sense to try to show a modal window after closing the parent window (hence why your code can't work). Not sure what you're trying to achieve... I have an excel add-in and when someone clicks "Place and Next" its to do its operation, move down a row in excel, and reopen the same form again. Link to comment Share on other sites More sharing options...
0 firey Posted September 28, 2013 Share Posted September 28, 2013 Basically in order to do something like that.. you would have something like: private void openChildWindow() { MyChildForm childForm = new MyChildForm(); childForm.ShowDialog(); } then you just have an event every cell click like, or during your "Pick and Next" you would call the function. private void Cell_Click(Object sender, EventArgs e) { openChildWindow(); } It doesn't make sense to open an instance of a child form inside of the child form. You need a parent to control that. Link to comment Share on other sites More sharing options...
0 Kalint Posted September 28, 2013 Author Share Posted September 28, 2013 Basically in order to do something like that.. you would have something like: private void openChildWindow() { MyChildForm childForm = new MyChildForm(); childForm.ShowDialog(); } then you just have an event every cell click like, or during your "Pick and Next" you would call the function. private void Cell_Click(Object sender, EventArgs e) { openChildWindow(); } It doesn't make sense to open an instance of a child form inside of the child form. You need a parent to control that. Ah well that explanation makes much more sense. Link to comment Share on other sites More sharing options...
0 firey Posted September 28, 2013 Share Posted September 28, 2013 Ah well that explanation makes much more sense. You get it all figured out? Link to comment Share on other sites More sharing options...
0 Kalint Posted September 28, 2013 Author Share Posted September 28, 2013 You get it all figured out? Yes I have, thanks! Link to comment Share on other sites More sharing options...
0 firey Posted September 28, 2013 Share Posted September 28, 2013 Yes I have, thanks! Awesome :D no problem. Link to comment Share on other sites More sharing options...
Question
Kalint
Soooo.... when I call this method, is it actually closing the current form and reopening a new one; or is the previous form still hidden :/
Link to comment
Share on other sites
7 answers to this question
Recommended Posts