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.