简体   繁体   English

winform用户控件中的自定义事件

[英]Custom event in a winform usercontrol

I am adding a usercontrol dynamically to a winform.我正在将用户控件动态添加到 winform。 The user control has a custom event.用户控件有一个自定义事件。

form_load()
{
ucUpdateProgress ucUP = new ucUpdateProgress();
ucUP.customEvent += new EventHandler<CustomEventArgs>(ucUP_customEvent);
this.Controls.Add(new ucUpdateProgress());
}

I am calling this event when the user click the cancel button.当用户单击取消按钮时,我正在调用此事件。 But the customevent's value is null.但是自定义事件的值是 null。 Why is that?这是为什么? Whats wrong with my code?我的代码有什么问题?

private void button1_Click(object sender, EventArgs e)
    {
        CustomEventArgs cEA = new CustomEventArgs(true);
        customEvent(sender, cEA);
    }  

Thanks, Syd谢谢,西德

That should be那应该是

this.Controls.Add(ucUP)

not不是

this.Controls.Add(new ucUpdateProgress());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM