Changing properties of the control box (so-called in Visual Studio) may have some undesireable side-effects:
- Setting the control box property to false hides all components in the title bar, expect the title itself. So there will be no icon in the title bar, only in the task bar.
- If you hide the maximize control (MaximizeBox), some problems regard resizing the application occur:
- “aero snap” of your application isn’t visualized correctly (dragging it to the edge of your screen won’t resize the application).
- Also double clicking the title bar to maximize the window won’t work.
The following shows some effort trying to hide the close button programatically. My conclusion on this AFAIK - it’s impossible.
virtual property System::Windows::Forms::CreateParams^ CreateParams
{
System::Windows::Forms::CreateParams^ get() override
{
System::Windows::Forms::CreateParams^ overrideParams = Form::CreateParams;
// Make your changes to overrideParams members here
//overrideParams->ClassStyle = overrideParams->ClassStyle | 0×200; // only grayed it out
overrideParams->Style &= ~0×80000; // like ControlBox set to false:
return overrideParams;
}
}
Only grayed it out:
using namespace System::Runtime::InteropServices;
[...]
#define SC_CLOSE 0xF060
#define MF_GRAYED 0×1
[...]
// somewhere near initialization
myform::EnableMenuItem(GetSystemMenu(this->Handle, false), SC_CLOSE, MF_GRAYED);
[...]
[DllImport("user32.dll")]
static IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")]
static int EnableMenuItem(IntPtr hMenu, int wIDEnableItem, int wEnable);

