There is a certain point of view that would suggest that this isn't the best solution...
for example, you can never neatly exit the application with the above code.
There is a better soution that will grey out the x button, which also resolves the other main objection that the above code doesn't conform with what users expect.
If you do a search on "GetSystemMenu" you will very quickly come up witha whole stack of answers and arguments for& against each method!
Take Care
Matt
If at first you don't succeed, skydiving is not for you.
I must confess that I have never seen the logic in disabling the X. Put any cleanup code needed in either the form unload event or form terminate event depending on what you are trying to clean up.
The code will fire when the user clicks the X or whatever else you are using to close. (close button, code from another form etc, etc)
App works the way the user expects.
Please note, I do not wish to insult end users, but many have little concept of using an app. They expect things to work one way and get "upset" when things do not work that way.
Our job is to develop apps that they can and will use.
What I mean is that if a user encounters a command button that is ungreyed (enabled to you, me and other programmers) they expect "it" to do something if they click it and vice versa. Therefore to have a button that does nothing when enabled is confusing!
Take Care
Matt
If at first you don't succeed, skydiving is not for you.
Having read many of your answers, I know you are much more expert than I.
And we may be on the same wave length about the desireability of disabling the X button
Users expect to be able to close a form using that button.
The only use I can gather from disabling the X button is to make certain clean up code fires.
This can be accomplished by placeing the cleanup code in either the form unload event (for most code, probably the best way) or in the form terminate event(necessary for some code such as setting a minimized form to maximized when the current form is closed Try it in the Unload event see why)
I feel that it is better to handle the cleanup without disabling the X.
Now if somebody would show me that I am wrong, I would greatly appreciate it since I learn by my mistakes (I guess that is why I am so smart. I make a lot of mistakes. think about it)
To keep the standard Windows interface, either disable the control, or remove all three by setting the form's ControlBox property to False
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'If we're supposed to work in Hex, why have we only got A fingers?'
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.