Click here to Skip to main content
15,936,903 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i had three forms,
in second form when i click on settings form, settings form will be opened. if any changes are made in the settings form and after saving the settings, settings form will be closed and second form also should be closed and first form should be opened.
if no changes are done in settings and simply click on close settings form will be closed...

if any changes are made and click on save button then only both the settings(form3) and form2 should be closed..
can you please help in this..
CHill60 30-Mar-15 10:55am    
What have you tried?
prasadpp26 30-Mar-15 11:25am    
Need to Implemet State managements Before Saving and After Saving.
CHill60 30-Mar-15 11:31am    
Use the Improve question link to post the code you have tried and explain where you are stuck
BillWoodruff 30-Mar-15 14:18pm    
Assuming this is a WinForms application: what is the Main Form ? Is it the case that you need to close the Main Form while keeping the application "alive" ? Yes ... this is possible, though not done very often.

1 solution

1.declare any global variable or flag where you can set that is there any changes happened or not. Its simple.
2. You have to check that variable's value on close button click. Here is the code to get that.
private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
    if (string.Equals((sender as Button).Name, @"CloseButton"))
        // Do something proper to CloseButton.
        // Then assume that X has been clicked and act accordingly.

Source : Click Here[^]

3. Closing form and opening form.

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