Custom event in a winform usercontrol
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());
精彩评论