The idea is to do basic math to find the difference in size between the object and the form.
To do this take the object size (int1, int2) and the form size (int1_1, int2_2) then get the difference by subtraction.
The math is (int1 - int1_1, int2 - int2_2) so it's fairly simple and straight forward.
For this example we will automatically set up the size of the form and the panel we will be resizing on form load.
void Form1_Load()
{
this.Size = new System.Drawing.Size(566, 461);
panel1.Size = new System.Drawing.Size(526, 399);
}
Now to get the difference in sizes. To do this, subtract panel size from form size.
566 - 526 = w
461 - 399 = h
In this particular case the difference is (40, 62)
w = 40
h = 62
Now for the re-size event. Just set the panel size to an integer equal to the form size's difference.
void Form1_Resize(object sender, EventArgs e)
{
int formH = this.Size.Height;
int formW = this.Size.Width;
h = formH - 62;
w = formW - 40;
panel.Size = new System.Drawing.Size(w, h);
}
Now we still have to declare h and w as public integers at the top of the source. We put this after the InitializeComponent void. If we don't we get errors. :(
public int h;
public int w;
You're welcome. :D If you need help just ask. :)