Demonstrates how to disable the close button in C#.

private const int SC_CLOSE = 0xF060;
		private const int MF_GRAYED = 0x1;

		[DllImport("user32.dll")]
		private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

		[DllImport("user32.dll")]
		private static extern int EnableMenuItem(IntPtr hMenu, int wIDEnableItem, int wEnable);

		private void Form1_Load(object sender, System.EventArgs e)
		{
			EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_GRAYED);
		}

All right, but this is only good for disabling the button for good. And what if I want to enable it later, after clicking a button on my form?

Here is the code for enabling and disabling the close "x" button, Use a flag variable to toggle the state.

        if (flag == true)
        {
            EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_ENABLED);
        }
        else
        {
            EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_GRAYED);
        }

And what about MF_ENABLED? Is MF_ENABLED=0x0 ?

Here is what you are looking for

internal const UInt32 MF_ENABLED =0x00000000;
internal const UInt32 MF_GRAYED =0x00000001;
internal const UInt32 MF_DISABLED =0x00000002;