disable close 'x' button in winform
Published: 15. December 2008 | Updated: 15. December 2008License: Microsoft Public License (MS-PL)
Categories: Windows » Win32, Winforms
Tags: C# UI Windows Winforms
Snippet shows how to disable close 'x' button in Winforms
Import namespace
using System.Runtime.InteropServices;
Import extern methods
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);
Use
IntPtr hMenu = GetSystemMenu(this.Handle, false); int menuItemCount = GetMenuItemCount(hMenu); RemoveMenu(hMenu, menuItemCount - 1, MF_BYPOSITION);
| Send us feedback about this snippet » |





