How to dynamically remove a UserControl in c # .net from the form?


I have a UserControl that is dynamically added to a FlowLayoutPanel . In that same UserControl I have a button to remove itself if the user wants, obviously at runtime. I need to delete it from Form . I tried this but nothing happened because the "Children" does not recognize me:

asked by JaviYeri 14.06.2018 в 06:47

2 answers


The best answer and it was useful for me was given in StackOverflow in English. As it is not duplicated in Spanish I leave it and I do not eliminate the question. Thanks to everyone!

Click here to go to the answer to the same question in this thread

answered by 17.06.2018 / 05:23

Hi, I'll leave you an example working. In the click event of the button that you have in your UserControl we have:

 private void button1_Click(object sender, EventArgs e)


In the original Form you should enter this:

 this.userControl11.Parent = this;

I hope it helps you.

answered by 14.06.2018 в 08:05