如何禁用表单中的“关闭”按钮

时间:2011-04-08 07:09:50

标签: c# windows

  

可能重复:
  How to make the Close button disabled in a windows Form using C# coding

我想在表单中禁用“关闭”按钮,任何人都可以帮助我。

1 个答案:

答案 0 :(得分:0)

以下内容应该有所帮助:

[DllImport("user32.dll")]
private static extern int GetSystemMenu(int hwnd, int revert);

[DllImport("user32.dll")]
private static extern int GetMenuItemCount(int menu);

[DllImport("user32.dll")]
private static extern int RemoveMenu(int menu, int position, int flags);

private void DisableCloseButton()
{
   int menu = GetSystemMenu(Handle.ToInt32(), 0);
   int count = GetMenuItemCount(menu);
   RemoveMenu(menu, count - 1, MF_DISABLED | MF_BYPOSITION);
}
相关问题