The accepted answer offers a possible workaround for the problem (and one that I have used many times), but it just does not answer the question that was originally asked:
How / why does maximizing or minimizing the form cause the close button to turn on again after it is disabled using the GetSystemMenu and EnableMenuItem API functions?
I came to this question during a completely barren Google search after discovering this seemingly inexplicable behavior for myself. Not finding the answer that actually explained the behavior, I was forced to resort to some digging of my own.
For reference, please note that the same code as in the original question works fine in the native Win32 application. Re-enabling the Close menu item appears to be limited by WinForms applications.
Examining the source code for the System.Windows.Forms.Form class reveals an interesting implementation detail: The .NET Framework developers apparently decided to set up the form's system menu every time the WindowState form changes , which includes maximizing and minimizing events sent by the system .
In particular, there are two methods called AdjustSystemMenu , which are responsible for changing the system menu in response to these events (and ruined any setting that you may have made yourself). If you are interested in learning the code (which I refrained from posting here for the benefit of those involved in projects such as Mono), grab a free copy of .NET Reflector .
I'm not quite sure why this decision was made, but at least I have an explanation.
source share