Please ask yourself if you intend to write code
only you will understand: if the answer is "no," read on. If you want to get a job as a programmer in the future, please read on.
A UserControl is a ContainerControl; so is a FlowLayoutPanel. You add Controls to the ControlCollection of a ContainerControl, and the ContainerControl can be accessed from the added Controls by their Parent Property (which returns a generic Control instance).
Consider the way elements are named and used in this example:
private Dictionary<Button, BtnContainer> BtnToBtnContainer = new Dictionary<Button, BtnContainer>();
private int bcntCount = 0;
private int btnCount = 0;
private void btnAddBtnContainer_Click(object sender, EventArgs e)
{
BtnContainer bcntNew = new BtnContainer();
bcntNew.Name = $"bcnt_{bcntCount++}";
Button btnNew = new Button();
btnNew.Name = $"btn_{btnCount}";
btnNew.Text = btnCount.ToString();
btnCount++;
BtnToBtnContainer.Add(btnNew, bcntNew);
bcntNew.Controls.Add(btnNew);
btnNew.Click += BtnNewOnClick;
flowLayoutPanel1.Controls.Add(bcntNew);
}
private void BtnNewOnClick(object sender, EventArgs e)
{
Button btn = sender as Button;
BtnContainer bcnt = BtnToBtnContainer[btn];
switch (Int32.Parse(btn.Text))
{
case 1:
break;
}
}
Notes:
1) I used a dictionary here to look up the Parent UserControl; that's kind of a frill since you can easily cast the Parent Property to its native Type; my motive was to to get you thinking about what
else you could use a Dictionary (or some other data structure) for in the future.