This is code for disable MessageBox Close button using C#.net
MessageBox.Show("Are you sure, Do you want to Close this Application?","Application Name",MessageBoxButtons.YesNo);
internal const int SC_CLOSE = 0xF060;
internal const int MF_GRAYED = 0x1;
internal const int MF_ENABLED = 0x00000000; //enabled button status
internal const int MF_DISABLED = 0x00000002; //disabled button status
[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr HWNDValue, bool Revert);
[DllImport("user32.dll")]
private static extern int EnableMenuItem(IntPtr tMenu, int targetItem, int targetStatus);
internal const int MF_GRAYED = 0x1;
internal const int MF_ENABLED = 0x00000000; //enabled button status
internal const int MF_DISABLED = 0x00000002; //disabled button status
[DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr HWNDValue, bool Revert);
[DllImport("user32.dll")]
private static extern int EnableMenuItem(IntPtr tMenu, int targetItem, int targetStatus);