none
Which event is fired when the big red X is clicked?

    Question

  • Hi,

    I am writing a C# plug-in for AutoCAD. I have 2 forms and when I click on the big red X of the second form, AutoCAD will hang and I have to kill the process. I have a Quit button programmed that does the job but I need to trap the big red X event.

    I tried the Form.Disposed event handler but it doesn't work. Which one is it?

    My Quit button works as follows:

             private void btnQuit_Click(object sender, EventArgs e)
            {
                this.Hide();
                e1.Close();
            }

    If anyone can shed some light on this, it would be great. thanks.

    Sean
    • Changed type Bruce.Zhou Monday, February 23, 2009 2:22 AM Not followed up in time
    • Changed type Bruce.Zhou Tuesday, February 24, 2009 3:19 AM Customer comes back with solution
    Tuesday, February 17, 2009 3:41 PM

Answers

  • Form_Closing(...) and Form_Closed (...) are the two events called when you click the X
    www.myspace.com/deodorant
    • Marked as answer by Bruce.Zhou Tuesday, February 24, 2009 3:20 AM
    Tuesday, February 17, 2009 5:04 PM
  • Hi sean,

    Yes, as deodorant said, Form_Closing and Form_Closed event will be fired when you click the "X" button. The code in your quit button click event handler doesn't close the second form, but just hide it. So I guess there is some other error which causes your application hung. Would you please post a little more code?

    Best regards,
    Bruce Zhou


    Please mark the replies as answers if they help and unmark if they don't.
    • Marked as answer by Bruce.Zhou Tuesday, February 24, 2009 3:20 AM
    Thursday, February 19, 2009 5:22 AM
  • Mt thanks to everyone with their suggestions. I was able to get it to work correctly by changing the code as follows where e1 is the first form and e2 is my second form that needed the event to be trapped:

            private void btnQuit_Click(object sender, EventArgs e)
            {
                this.Hide();
                e1.Close();
            }

            void e2_FormClosing(object sender, FormClosingEventArgs e)
            {
                e1.Close();
            }

    I have changed the architecture of my app to include a factory design pattern. I am now treating the forms differently. It was a big help to have everyone's suggestions on the matter.

    Sean
    • Marked as answer by Bruce.Zhou Tuesday, February 24, 2009 3:20 AM
    Monday, February 23, 2009 4:11 PM

All replies

  • Form_Closing(...) and Form_Closed (...) are the two events called when you click the X
    www.myspace.com/deodorant
    • Marked as answer by Bruce.Zhou Tuesday, February 24, 2009 3:20 AM
    Tuesday, February 17, 2009 5:04 PM
  • Hi sean,

    Yes, as deodorant said, Form_Closing and Form_Closed event will be fired when you click the "X" button. The code in your quit button click event handler doesn't close the second form, but just hide it. So I guess there is some other error which causes your application hung. Would you please post a little more code?

    Best regards,
    Bruce Zhou


    Please mark the replies as answers if they help and unmark if they don't.
    • Marked as answer by Bruce.Zhou Tuesday, February 24, 2009 3:20 AM
    Thursday, February 19, 2009 5:22 AM
  • We are changing the issue type to “General Discussion” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by opening the Options list at the top of the post editor window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
    Please mark the replies as answers if they help and unmark if they don't.
    Monday, February 23, 2009 2:22 AM
  • Mt thanks to everyone with their suggestions. I was able to get it to work correctly by changing the code as follows where e1 is the first form and e2 is my second form that needed the event to be trapped:

            private void btnQuit_Click(object sender, EventArgs e)
            {
                this.Hide();
                e1.Close();
            }

            void e2_FormClosing(object sender, FormClosingEventArgs e)
            {
                e1.Close();
            }

    I have changed the architecture of my app to include a factory design pattern. I am now treating the forms differently. It was a big help to have everyone's suggestions on the matter.

    Sean
    • Marked as answer by Bruce.Zhou Tuesday, February 24, 2009 3:20 AM
    Monday, February 23, 2009 4:11 PM