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 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. 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());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.