Hello! I'm writing a text editor in C# and I have it so when the user is to close the program and the open document has been edited it prompts the user with a DialogBox asking them to save. Here is the code:

protected override void OnFormClosing(FormClosingEventArgs e)
        {
                if (e.CloseReason == CloseReason.WindowsShutDown) return;
                if (changed == true)
                {
                    DialogResult savePrompt = MessageBox.Show("Would you like to save your doument?","Save this document?",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question);
                    if(savePrompt == DialogResult.Yes){
                        save();
                    }
                    else if (savePrompt == DialogResult.Cancel)
                    {
                        e.Cancel = true;
                    }
                }
                else
                {

                }
        }

Now the problem is when I select Yes to save it doesn't fire off the save() method I wrote. Any ideas? Thanks for any help!

Have you checked to see the code enters the if statements correctly down the save method call?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.