如何禁用窗体中的“关闭”按钮

本文关键字:关闭 按钮 何禁用 窗体 | 更新日期: 2023-09-27 17:49:33

可能重复:
如何使用C#编码在windows窗体中禁用关闭按钮

我想禁用窗体中的关闭按钮,任何人都可以帮助我。

如何禁用窗体中的“关闭”按钮

以下内容应该会有所帮助:

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