去掉/禁止系统菜单里的MOVE的方法

针对论坛上的问题“如何禁止在标题栏上点右键”,有如下方法:

1。用API去掉Move,

[DllImport(“user32.dll”,EntryPoint=”GetSystemMenu”)]
extern static System.IntPtr GetSystemMenu(System.IntPtr hWnd , System.IntPtr
bRevert);

[DllImport(“user32.dll”,EntryPoint=”RemoveMenu”)]
extern static int RemoveMenu (IntPtr hMenu, int nPos, int flags);

static int MF_BYPOSITION = 0x400;
static int MF_REMOVE = 0x1000;

System.IntPtr hdl= GetSystemMenu(this.Handle,System.IntPtr.Zero);
int nflag =MF_BYPOSITION | MF_REMOVE;
int npos =1;
RemoveMenu(hdl,npos,nflag);

2。去掉系统菜单(不推荐)

private const int WS_SYSMENU = 0x00080000;

protected override CreateParams CreateParams
  {
   get
   {
    CreateParams cp =  base.CreateParams;
    cp.Style = cp.Style & ~WS_SYSMENU;
    return cp;
   }
}

示范代码如下