UserControl is not Resizing in Panel

646 Views Asked by At

I'm having a problem using user controls with panels. When I load user control into the panel with the code:

 panel3.Controls.Add(new userControl1());

it loads with the size of my initial usercontrol1 size. Actually, I have already made my form to maximize with this code.

 this.MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
 this.WindowState = FormWindowState.Maximized;

I also tried all the solutions I was able to find. 1- I tried to Dock Fill with the panel, user control, Anchoring to all sides. 2- Also did AutoSize = True for user control and panel. Nothing works at this point.

Actually, when I first time did load user control into the panel it loaded okay in my original project. then I don't know what happened. The image uploaded below is captured from the scratch new project. So, be sure it's not a problem with my original project either.

Sample Problem Project

1

There are 1 best solutions below

1
Dimitri Merkling On

I Think you're looking for this : https://stackoverflow.com/a/10871592/16165399

In your UserControl : this.Dock = DockStyle.Fill;