欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【C#】禁用 Windows窗体右上角的关闭按钮

程序员文章站 2022-06-08 23:12:54
...
public partial class Form1 : Form
    {
        [DllImport("USER32.dll")]
        public static extern int RemoveMenu(int hMenu, int nPosition, int wFlags);

        [DllImport("USER32.dll")]
        public static extern int GetSystemMenu(int hWnd, int bRevert);

        const int MF_REMOVE = 0x1000;
        const int SC_CLOSE = 0xF060;

        public Form1()
        {
            //do something

            int hMenu = GetSystemMenu(this.Handle.ToInt32(), 0);
            RemoveMenu(hMenu, SC_CLOSE, MF_REMOVE);

            //do something
        } 
    }

 

相关标签: C#