WPF disable the Close 'X' button in a Window (c# .net) wpf禁止窗体右上角的关闭x按钮(让它变成灰色)

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

你可能感兴趣的:(.net,C#,user,button,WPF,WinForm)