rturney
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?
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?
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
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.reCenterEVaf terDwgClos e == true)
{
Form1.ActiveForm.Top = EViewMethods.form1CenterTo p;
Form1.ActiveForm.Left = EViewMethods.form1CenterLe ft;
}
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.
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.reCenterEVaf
{
Form1.ActiveForm.Top = EViewMethods.form1CenterTo
Form1.ActiveForm.Left = EViewMethods.form1CenterLe
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
in the windowstyle properties there is a boolean property that is MaximizeBox you can set that to false
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.
ASKER
Thanks for your help!
Best regards,
-Bob
Best regards,
-Bob