Trapping a Minimize button click

G

Guest

Can anybody help me figure out how to trap when a user clicks on the 'X' (minimize button) of a form? I have tried the resize, deactivate events -- but none indicate that the Minimize button caused these events to happen. I just want to prompt the user if they want to save changed data prior to going to another form. I have spent a lot of time on google -- with no luck, but I would have thought this was very straightforward. I also don't want to turn the minimize button off -- and force the rebuilding of that form again if the user want to access it later on.

Thanks for your help!

MSM
 
T

Tom Krueger [MSFT]

This does seem to be more difficult than it should be. How about using the
closing event? You will need to set the MinimizeBox property on the form
to false so it fires. Then in the closing event you could do your
validation. If the form is invalid you can set Cancel to true. If the form
is valid you still will need to set the Cancel to true, however, then Hide
the form.
private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e) {

if (txtConnString.Text.Length > 0) {
e.Cancel = true;
return;
}

e.Cancel = true;
this.Hide();
}

I will try to find a better answer for you. Let me know if you find
anything.

Tom


--
Tom Krueger
Microsoft Corporation
Program Manager
http://weblogs.asp.net/tom_krueger

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


MSM said:
Can anybody help me figure out how to trap when a user clicks on the 'X'
(minimize button) of a form? I have tried the resize, deactivate events --
but none indicate that the Minimize button caused these events to happen. I
just want to prompt the user if they want to save changed data prior to
going to another form. I have spent a lot of time on google -- with no
luck, but I would have thought this was very straightforward. I also don't
want to turn the minimize button off -- and force the rebuilding of that
form again if the user want to access it later on.
 
G

Guest

That is exactly the workaround to this issue that I implemented. But now -- the user sees the 'ok' button instead of the 'X' and that could be confusing to some users as it differs from the PPC standard. We have moved on to other issues -- but if you have any ideas in the future about how we could keep the Smart Minimize 'X' button instead of the 'ok' -- i would really appreciate it.

Thanks Tom,

MSM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top