Click here to Skip to main content
15,907,493 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I need some help regarding windows form applications.
Say I have 2 forms. I want to navigate away from my parent form and move to a child form. The problem is closing the parent form.
Using this.close closes all forms.
Any idea how this is done? thank you.

I need to close the first form since I edited it so that it wouldn't have a title bar (hence no minimize/maximize/close).. I need it that way. The problem with this way is that it never closes.
Posted
Updated 23-Feb-11 5:11am
v2

The first Form to Run() on starting an application is regarded as the Main Form and closing it will close the application.

Why you feel the need to close it just because the user is on another Form in the application is a mystery to me.

If it is because you do not want to allow the user to go back to the Main Form whilst the second Form is open, then make the second Form a Modal Form by using Form2.ShowDialog() instead of just Form2.Show(). That way your Main Form cannot be accessed until Form2 closes.

If there is another reason, then perhaps you could edit your question to explain it so that you get relevant answers.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Feb-11 16:19pm    
Correct explanation, my 5.
I tried to do it just for LOLs (by curiosity out of different question). You can run Application.Run more then once, this is the only way (see my Answer). I did not finish: logic gets tricky. Abuse is abuse, avoiding it the best answer :-)
--SA
Try setting the Visible property on the parent form to false instead of closing it. You may also want to manage the visibility of the form in the taskbar.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Feb-11 16:16pm    
Certainly the option, my 5. The original idea is really bad.
--SA
These are not "parent" and "forms"! They may or may not be in Ownership relationship: one in main form and the Owner of another "Owning Form". In both cases, this is expected behavior. The way to change main form it to call Application.Run (see your entry point) again. You can do it, you gave you the recipe. Advice is: avoid it by any means!

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900