I recently came acorss something that I have never really given much thought to before, when opening a new form and closing the current, I usually just hide the current and Show the new form using the ShowDialog method:
Form2 nextForm = new Form2();
this.Hide();
nextForm.ShowDialog();
this.Close();
However I was using the ShowDialog to actually get a DialogResult the other day and thought, why don't I just use the normal show method when opening and closing forms, but if I run the same code replacing ShowDialog with Show, the application closes as soon as form2 is opened.
Using the showDialog method above I am guessing that it will have the effect, that if you have a form leading onto another and another etc, all the previous forms will still be in memory and have some kind of performance impact.
Solution :
the code must be written like this
Form2 obj = new Form2();
obj.Show();
this.Hide();
Show dialog will set form2 as a modal dialog box
ShowDialog()
this.Close()
when this method is called any managed resource can be easily closed, but when dispose() method is called it will permanently remove the form from the memory
How to Open a new form and close the current, without hiding and closing the application
Posted by
Sweet Heart
On
10:03 AM
Subscribe to:
Post Comments (Atom)
0 Response to "How to Open a new form and close the current, without hiding and closing the application"
Post a Comment