Link to home
Start Free TrialLog in
Avatar of rturney
rturneyFlag for United States of America

asked on

Can you detect the Form's "X" when it is clicked?

Hello to all,

I am wondering if it is possible to detect a Form's "X" (next to the Maximize symbol in upper right corner of the form) when it is clicked?
Avatar of p_davis
p_davis

don't know quite what you are needing but that will raise the forms closing/closed event and you can do whatever you want there
Avatar of rturney

ASKER

Sigh,  It's a long story, but I have been trying to get the 1st Form (that calls a second form) to recenter itself after the second one closes.  The 1st gets put into the upper right corner by another method.  I had code in a Button on the second form to handle the re-centering of the first form and using this.Close() to dispose it.  I wanted to force the user to use the button's method instead of the "X"'s FormClosing.  

Your answer is correct that the FormClosing event will be triggered, but the event doesn't reveal that the "X" was the trigger.  

At any rate, my routines in the button click event were not doing what I thought they were.  And I just realized this after I posted this question.  It was throwing an exception when it hit

                Form1.ActiveForm.Select();
                if (EViewMethods.reCenterEVafterDwgClose == true)
                {
                    Form1.ActiveForm.Top = EViewMethods.form1CenterTop;
                    Form1.ActiveForm.Left = EViewMethods.form1CenterLeft;
                }

that was being caught by the "catch" which had no code...my bad!

I think I am going to have to use a delegate to inform the 1st Form that Form2 has closed.
ASKER CERTIFIED SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
in the windowstyle properties there is a boolean property that is MaximizeBox you can set that to false
Avatar of rturney

ASKER

Thank you, I did not know you could do that.  That is a valuable piece of information.  Even though I think the delegate approach is what I have to do to solve the underlying problem, you have helped me.
Avatar of rturney

ASKER

Thanks for your help!
Best regards,
-Bob