答案 0 :(得分:0)
您可以使用Windows API执行此操作。
这段代码可以解决问题:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace BlogConsole
{
class API
{
[DllImport("user32.dll")]
static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem, uint uEnable);
[DllImport("user32.dll")]
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
internal const UInt32 SC_CLOSE = 0xF060;
internal const UInt32 MF_ENABLED = 0x00000000;
internal const UInt32 MF_GRAYED = 0x00000001;
internal const UInt32 MF_DISABLED = 0x00000002;
internal const uint MF_BYCOMMAND = 0x00000000;
public static void EnableCloseButton(IntPtr handle, bool bEnabled)
{
IntPtr hSystemMenu = GetSystemMenu(handle, false);
EnableMenuItem(hSystemMenu, SC_CLOSE, (uint)(MF_ENABLED | (bEnabled ? MF_ENABLED : MF_GRAYED)));
}
}
}
这就是你的称呼方式:
static void Main(string[] args)
{
IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;
API.EnableCloseButton(handle, false);
}