I have been looking for some time on ways to open a second form from another already shown form.
This is some piece of code that works:
frmSecond second = new frmSecond();
this.Hide();
second.ShowDialog();
this.Close();
What it does basically is to Hide()
the currently opened form, then it opens another form (the ShowDialog()
method). It will only Close()
the currently hidden form when the form you have just created is closed.
The problem here is: this way of doing it creates an immense thread of forms. If I need to go from frmSecond
to frmThird
, it will maintain the first form and the frmSecond
being executed in the background, while only showing the frmThird
.
Then, as the frmThird
is open, if I need to get back to the first form, I would use some code like:
frmFirst first = new frmFirst();
this.Hide();
first.ShowDialog();
this.Close();
And it would create another frmFirst
! Then we would have three forms being executed in the background (the first frmFirst
, frmSecond
, and frmThird
).
This method works, but uses an increasingly amount of processing memory, which may be prejudicial for any kind of project.
Is there any alternative or add up to correct this problem?
If anything is unclear, please don't bother in letting me know. Thank you.