禁用和启用windows form窗体上的关闭按钮

本文介绍了一个C#窗体应用程序中如何根据初始化参数控制窗体右上角关闭按钮的有效性。通过设置CreateParams的ClassStyle属性,可以实现禁用或启用窗体的关闭按钮。

 1public partial class Form1 : Form
 2ExpandedBlockStart.gifContractedBlock.gif    {
 3        private bool isEnableCloseButton = false;
 4        public Form1(string strFlag)
 5ExpandedSubBlockStart.gifContractedSubBlock.gif        {
 6            InitializeComponent();
 7            if (strFlag == "no")
 8ExpandedSubBlockStart.gifContractedSubBlock.gif            {
 9                this.lbl_CloseButtonIsEnabled.Text = "窗体右上角关闭按钮无效";
10                this.isEnableCloseButton = false;
11            }

12            else
13ExpandedSubBlockStart.gifContractedSubBlock.gif            {
14                this.lbl_CloseButtonIsEnabled.Text = "可以通过窗体右上角关闭按钮 关闭窗体";
15                this.isEnableCloseButton = true;
16            }

17        }

18
19        protected override CreateParams CreateParams
20ExpandedSubBlockStart.gifContractedSubBlock.gif        {
21            get
22ExpandedSubBlockStart.gifContractedSubBlock.gif            {
23                if (isEnableCloseButton)
24ExpandedSubBlockStart.gifContractedSubBlock.gif                {
25                    CreateParams parameters = base.CreateParams;
26                    return parameters;
27                }

28                else
29ExpandedSubBlockStart.gifContractedSubBlock.gif                {
30      int CS_NOCLOSE = 0x200;
31                    CreateParams parameters = base.CreateParams;
32                    parameters.ClassStyle |= CS_NOCLOSE;
33                    return parameters;                    
34                }

35            }

36        }

37}

38

转载于:https://www.cnblogs.com/djbone/archive/2008/08/12/1266344.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值