开发者

Custom event in a winform usercontrol

开发者 https://www.devze.com 2023-03-21 14:59 出处:网络
I am adding a usercontrol dynamically to a winform. The user control has a custom event. form_load() {

I am adding a usercontrol dynamically to a winform. The user control has a custom event.

form_load()
{
ucUpdateProgress ucUP = new ucUpdateProgress();
ucUP.customEvent += new EventHa开发者_如何学运维ndler<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. 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());
0

精彩评论

暂无评论...
验证码 换一张
取 消