How can I close two forms I have, while having opened the third one?

Hello guys,

let me try to explain my problem as best as possible. I have two forms, one of which opens the other. So I have FirstForm, which on some button click calls the SecondForm constructor and that SecondForm constructor takes the reference to FirstForm. So somewhere in my FirstForm I have something like this:

SecondForm second = new SecondForm(this); second.Show(); 

Then in my SecondForm I have some input and when the user clicks the button, I want to close both the FirstForm and the SecondForm and open ThirdForm. But, I have trouble doing it.

Here is the code somewhere in my SecondForm:

ThirdForm third = new ThirdForm(); third.Show(); referenceToFirstForm.Close(); // I saved the reference from the constructor in a property Close(); 

However, this closes my entire application. I also tried using ShowModal() instead of Show(), but it keeps my other forms alive.

So again, what do I want to do? In the beginning, I want to show FirstForm. Then, when the user clicks something, I want to show SecondForm. However, when the user clicks something on the SecondForm I want to close both FirstForm and SecondForm but open up ThirdForm.

Any ways to do this?

Thanks in advance!

submitted by /u/The_Grey_Wolf
[link] [comments]

Leave a Reply