initializeComponent还真脆弱

我在Form1.Designer.cs中添加了匿名委托

    this.btnEvent.Click += new System.EventHandler(this.MyEventClick);//a event of mine
    this.btnEvent.Click += new System.EventHandler(delegate(object sender, EventArgs e)
            {
                MessageBox.Show("I have no name", "AnonymousMethodOfbtnEvent", MessageBoxButtons.OKCancel);
            });
结果报告了下面的错误:

“The designer cannot process the code at line 90:(这里是我上面的代码)
The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified.Please remove any changes and try opening the designer again.”
意思是“设计器无法处理第90行的代码:(这里是我上面的代码)。方法“initializeComponent”内的代码由设计器生成,不应手动修改。请移除任何更改,然后尝试重新打开设计器”。
所以我只好移往Form1.cs:         
    public Form1()
    {
        InitializeComponent();
        btnEvent.Click += new System.EventHandler(delegate(object sender, EventArgs e)
        {
            MessageBox.Show("I have no name", "AnonymousMethodOfbtnEvent", MessageBoxButtons.OKCancel);
        });
    }

不过它说得吓人--“请移除任何更改,”,结果我加行中规中矩的代码,也没问题:

this.btnEvent.Click += new System.EventHandler(this.MyEventClick);//a event of mine

转载于:https://www.cnblogs.com/Oneirictouch/archive/2009/12/03/1616516.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值