Using WinForms in C#, I’m struggling to get an embedded user control to resize correctly. I can add it to the panel with no issue, and the panel resizes as I expect (and want) it to.
To add the UserControl, I’m doing the following:
content.Controls.RemoveAt(0);
content.Controls.Add(c);
content.Controls[0].Dock = DockStyle.Fill;
content.Refresh();
I cannot figure out how to get the newly added control to resize properly, I’ve also tried using Anchor with Top,Bottom,Left,Right but to no avail. Any help would be appreciated, thanks.
Adding below will resize the user control with the parent control size.
But, if you want to resize the child controls of your user control you will have to set their dock values and anchor values properly. Otherwise, the main user control will resize but the inner child controls of the user control will stay as they are.
You have said;
<< the control moves down, instead of resizing down
If there are some child controls that you want to stretch vertically you might try FlowLayout panel.