Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m facing a task. i hve tried a lot but of no great success.
is it possible to close parent form from child form.

Can you guys guide me or refer me some USEFUL link which is really useful
Posted
Updated 11-Dec-11 7:54am
v2

First thing to understand is: there is not functional relationship parent/child between forms. Please see my past answer: Parent Child Form Relationship[^]. Even though a form is a Control with this relationship, it is made defunct for forms.

Now, the main form is a special one: it is defined by the instance passed to Application.Run. If you close a main form, the whole application (but not the application process) will exit.

Your request is a sing of a flaw in the whole application design. However, there are some cases where the effect you want might be needed.

So, there are at least two approaches.

First, most simple and reasonable is this one: never close the main form but make it hidden instead. This is quite simple.

Another approach is running the singleton Application twice or more than two times: first with one instance of the form, another time with another one, etc. Look at your method Main and modify it according to your logic.

For example, please see a code sample I provided in response to a similar question: Windows Form application[^].

—SA
 
Share this answer
 
you can close whole application by application.exit();
 
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