For my current project I am adding an variable amount of usercontrols : ucTask to my flowlayoutpanel : flpTasks
foreach (task t in tasks)
{
ucTask uct = new ucTask();
uct.id = t.task_id;
uct.date= t.date.ToString();
uct.btnNaam = t.task_id.ToString();
uct.OnButtonclick += new EventHandler(uct_OnButtonclick);
flpTasks.Controls.Add(uct);
}

Now I will have a couple of those usercontrols in the flowlayoutpanel, and I want to fire an event when I press that button. With the EventHandler I can fire an event, but I need to fire a different event for a different button.
void uco_OnButtonclick(object sender, EventArgs e)
{
lblStatus.Text = "TEST";
}
I don’t know how to know which button (or usercontrol) I pressed. And I’m out of ideas, any suggestions?
Thanks,
Thomas
Sender of event is actually one of buttons. When you cast sender to Button type, you can access any of Buttons properties and determine which button was pressed:
UPDATE: after reading your question once again, I get that ucTask is actually UserControl, which rises event when button inside it was clicked.
So, first is naming. Good style for class names in c# is PascalCase. E.g. for task user control good name will be
TaskControl. Next goes event naming. It’s common to name events asEventName(-ing, -ed). If you want to raise event, then good style is protected methodOnEventName(-int, -ed). And another remark – when you writing user controls, you are free to use business terms to name your events. E.g. TaskCreated, TaskChanged. And you also can pass any parameters to your event by creating custom EventArgs.So, for your user control:
When you use your user control, just subscribe to its TaskChanged event:
And all parameters, that you passed via event argument will be available in that event handler: