Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6143323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:30:39+00:00 2026-05-23T18:30:39+00:00

I have a Form_Closing event that prompts the user if the file has been

  • 0

I have a Form_Closing event that prompts the user if the file has been changed to save if changes have been made to the file (standard Yes/No/Cancel options). Cancel is where things don’t work as they should.

If I select File -> New and there is an existing file with changes I get prompted as expected, bit when I select Cancel the new form is presented rather than staying on the current form and I end up with two forms open at once.

Here is MainForm (File New) code:

       if (editForm != null)
        {
            // Close existing Editor form
            editForm.Close();
            // Open new form
            editForm = new EditorForm(this);
            // Close Form Events
            editForm.Closing += new CancelEventHandler(EditorForm_Closing);
            editForm.Show();
            editForm.Focus();

      else
        {
            // Open new Editor 
            editForm = new EditorForm(this);
            // Close Form Events
            editForm.Closing += new CancelEventHandler(EditorForm_Closing);
            editForm.Show();
            editForm.Focus();
        }

Here is my EditForm_Closing:

  if (editForm != null)
        {
            if (editForm.diagramComponent.Model.Modified)
            {
                DialogResult res = MessageBox.Show(this, "The project has been modified. Save changes?", "Save changes", MessageBoxButtons.YesNoCancel);
                if (res == DialogResult.Yes)
                {
                    if (!editForm.HasFileName)
                    {
                        if (this.saveEditorDialog1.ShowDialog(this) == DialogResult.OK)
                        {
                            this.ActiveDiagram.SaveSoap(this.saveEditorDialog1.FileName);
                            editForm.FileName = this.saveEditorDialog1.FileName;
                        }
                    }
                    else
                    {
                        this.ActiveDiagram.SaveSoap(editForm.FileName);
                    }

                }
                else if (res == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
            }

Not sure how to make the correlation between the Cancel close event and my File -> New. Any help is greatly appreciated. Thank you.

EDIT: Added my EditForm_Closing Event.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:30:39+00:00Added an answer on May 23, 2026 at 6:30 pm

    Try replacing your main form’s code with the following:

    if (editForm != null) {
        // try closing existing Editor form
        editForm.Close();
        if(!editForm.IsDisposed) // close was canceled.
            return;
    }
    
    // Open new form
    editForm = new EditorForm(this);
    // Close Form Events
    editForm.FormClosing += new FormClosingEventHandler('suitable method here');
    editForm.Show();
    editForm.Focus();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an application (using Delphi 2009) that allows a user to select
I have a .Net application that uses their user settings. What is the best
I have a Hashtable that contains numerous EventLog objects. In my FormClosed event, I
i have a Form which has a button, on the button click event, a
I have one form that has an option to open another (dialogue). I want
I have a form which, among the other controls, has a TextBox field that
I have a static event in a DLL that I use frequently - Toolkit.Dialogs.ExitConfirm
I have form where user submits field. Field can have letters, numbers, and punctuation.
i have form with user data to input and javascript ajax to send information
We have an administrative portal that our teachers constantly forget to download their latest

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.