Reputation: 2145
I'm trying to figure out a easy way to re-size my child form based on the size of the parent form. i.e The child form pops out of the parent form (FixedToolWindow).
To do this presently i'm achieving this by having a OnParentResize event in my form child class. i.e
void OnParentResized(object sender, EventArgs e)
{
//Resize of the form shall be made only when the form is not minimized
if (parent.WindowState != FormWindowState.Minimized)
{
int iWidth = parent.Size.Width;
int iHeight = parent.Size.Height;
double dXFactor = (double)iWidth / (double)this.Width;
double dYFactor = (double)iHeight / (double)this.Height;
this.Scale(new SizeF((float)dXFactor, (float)dYFactor));
}
}
The line this.Scale(new SizeF((float)dXFactor, (float)dYFactor)); scales all the controls in my child form.
When i use this i presume that whenever the parent form resizes, my child form does as well. Apparently i face a problem here, all the controls inside the child form are anchored to top-left.
Initially all the controls in my child form are of normal size.
Parent form is resized to make it small, the child form shrinks to the same factor as well.
Now i increase the size of my parent form back to its original size. The size of the controls on the child form now increases by a higher ratio. And also the controls appear out of place.
Can anyone suggest a better approach for such situations.
Cheers
Upvotes: 2
Views: 11751
Reputation: 1241
Change in Parent From isMdiContainer as true, childform border style as none, then
in Parent form edit code like this in vent where you want.
foreach (var mdiChild in MdiChildren)
mdiChild.Close();
var childobj= new childform {MdiParent = this, Dock = DockStyle.Fill};
childobj.Show();
Edit the Controls to by an Anchor Property.
Hope it may helps to you.
Upvotes: 2
Reputation: 1074
I guess you have to use the ClientRectangle's width and height instead of the Window width and height. Because your client rect is smaller than your windows rectangle. This is a initial guess.
Upvotes: 0