I know this an old post, but I'd like to try to contribute anyway.
My problem was that the form that I was adding into my panel didn't automatically adjust its size when the parent panel had its size changed.
The problem was that I was doing this:
form.WindowState = FormWindowState.Maximized; // <-- source of the problem
form.AutoSize = true; //this causes the form to grow only. Don't set it if you want to resize automatically using AnchorStyles, as I did below.
form.FormBorderStyle = FormBorderStyle.Sizable; //I think this is not necessary to solve the problem, but I have left it there just in case :-)
panel1.Controls.Add(form);
form.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
form.Dock = DockStyle.Fill; //this provides the initial size adjust to parent' size.
form.Visible = true;
To solve, I just commented the first line //form.WindowState = FormWindowState.Maximized;
and everything worked like a charm.
Anchor
toBottom, Right
. If this actually works, it means that there are something wrong in the way things are done in your original form - see answers from others for figuring it out. If the new form does not work, I have NO idea what's wrong...