Windows Form窗体的关闭按钮的启用与否

public partial class Form1 : Form
    {
        private bool isEnableCloseButton = false;
        public Form1(string strFlag)
        {
            InitializeComponent();
            if (strFlag == "no")
            {
                this.lbl_CloseButtonIsEnabled.Text = "窗体右上角关闭按钮无效";
                this.isEnableCloseButton = false;
            }
            else
            {
                this.lbl_CloseButtonIsEnabled.Text = "可以通过窗体右上角关闭按钮 关闭窗体";
                this.isEnableCloseButton = true;
            }
        }

        protected override CreateParams CreateParams
        {
            get
            {
                if (isEnableCloseButton)
                {
                    CreateParams parameters = base.CreateParams;
                    return parameters;
                }
                else
                {
      int CS_NOCLOSE = 0x200;
                    CreateParams parameters = base.CreateParams;
                    parameters.ClassStyle |= CS_NOCLOSE;
                    return parameters;                   
                }
            }
        }
}

 

//调用显示该窗体
Form1 frm = new Form1("no");
frm.ShowDialog();

posted on 2008-08-12 18:01  freeliver54  阅读(1586)  评论(3编辑  收藏  举报

导航