WinForm中,屏蔽关闭按钮

来源:互联网 发布:黑客论坛网站源码 编辑:程序博客网 时间:2024/05/02 18:48

using System.Runtime.InteropServices;

 
[DllImport("user32.dll")]
  internal static extern IntPtr GetSystemMenu(IntPtr hwnd, bool bRevert);
  [DllImport("user32.dll")]
  internal static extern int GetMenuItemCount(IntPtr hMenu);
  [DllImport("user32.dll")]
  internal static extern int RemoveMenu(IntPtr hMenu, int uPosition, int uFlags);
 
  private void Form1_Load(object sender, EventArgs e)
  {
    CloseButtonEnable();
  }
 
  ///<summary>  
  ///「×」ボタンを不可用にする
  ///</summary>   
  private void CloseButtonEnable()
  {
   const int MF_BYPOSITION = 0x00000400;
   IntPtr hWindow = this.Handle;
   IntPtr hMenu = GetSystemMenu(hWindow, false);
   int count = GetMenuItemCount(hMenu);
   RemoveMenu(hMenu, count - 1, MF_BYPOSITION);
   RemoveMenu(hMenu, count - 2, MF_BYPOSITION);
  }
原创粉丝点击