首先在妳的窗體類中引入壹些Windows API需要的定義
const uint SC_CLOSE = 0xf060;
const uint MF_GRAYED = 0x01;
const uint MF_BYCOMMAND = 0x0;
[DllImport("user32.dll")]
static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem,
uint uEnable);
[DllImport("user32.dll")]
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")]
static extern bool RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags);
然後可以在窗體的Load事件中加入下列初始化代碼
IntPtr hSysMenu;
hSysMenu = GetSystemMenu(this.Handle, false);
EnableMenuItem(hSysMenu, SC_CLOSE, MF_GRAYED);
RemoveMenu(hSysMenu, SC_CLOSE, MF_BYCOMMAND);