using System.Runtime.InteropServices; const int MF_BYPOSITION = 0x400; [DllImport("User32")] private static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlags); [DllImport("User32")] private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert); [DllImport("User32")] private static extern int GetMenuItemCount(IntPtr hWnd); private void Form1_Load(object sender, EventArgs e) { IntPtr hMenu = GetSystemMenu(new WindowInteropHelper(this).Handle, false); // this.Handle here for winform. 如果是winform程序使用this.Handle 替代 new WindowInteropHelper(this).Handle int menuItemCount = GetMenuItemCount(hMenu); RemoveMenu(hMenu, menuItemCount - 1, MF_BYPOSITION); }
http://www.c-sharpcorner.com/UploadFile/itsraj007/Rajendra105292008020242AM/Rajendra1.aspx
http://www.eggheadcafe.com/community/aspnet/2/10045796/disable-x-button.aspx
本文介绍如何使用C#代码移除Windows窗口系统菜单中的指定菜单项。通过调用User32.dll中的API函数GetSystemMenu、GetMenuItemCount及RemoveMenu实现功能,适用于WinForms应用程序。

被折叠的 条评论
为什么被折叠?



