winform 禁用最大化最小化和关闭按钮

 

不能使用最大化窗口:MaximuzeBox 设为False
不能使用最小化窗口:MinimizeBox 设为False
不能使用红叉关闭
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);

        ///   <summary> 
        ///   窗体的关闭按钮失效 
        ///   </summary> 
        protected 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);
        }

        private void confirm_Load(object sender, EventArgs e)
        {
            CloseButtonEnable();

        }

 

其他


禁止combobox输入方法:将DropDownStyle 设为DropDownList
禁止Form窗口调整大小方法:FormBorderStyle 设为FixedSingle

posted on 2009-09-07 16:49  Master zhu  阅读(2208)  评论(0编辑  收藏  举报

导航