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);
        }

Edited 3 Years Ago by Nick Evan: Fixed formatting

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;

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.