[WinForm]使关闭按钮不可用或隐藏

关键代码:

        /// <summary>

        /// 代码源自:http://www.codeproject.com/Articles/20379/Disabling-Close-Button-on-Forms

        /// </summary>

        private const int CP_NOCLOSE_BUTTON = 0x200;

        protected override CreateParams CreateParams

        {

            get

            {

                CreateParams _createParams = base.CreateParams;

                _createParams.ClassStyle = _createParams.ClassStyle | CP_NOCLOSE_BUTTON;

                return _createParams;

            }

        }

代码效果:

image

或者设置ControlBox属性来隐藏,如图:

image

希望有所帮助!

你可能感兴趣的:(WinForm)