Setting MDI Parent Size To Fit Around A Child Form

A

Abby Brown

Hi,

How do you set the client size of an MDI parent to fit around a child form?
Breakpoints in the constructor and load event handler show the child size to
be already modified to fit into the parent; the child's size does not match
what shows in the Designer. I suppose the real question might be how do you
determine the size of the child window or keep the parent from changing it
first?

Thanks,
Gary
 
R

Roger Frost

What you're asking for is a little backwards, but I'm sure you have your
reasons.

At any rate, these are the properties you will want to investigate:

frmChild.Size
frmParent.ClientSize

and also frmParent.MdiChildren[] but I would resize the parent before the
child is shown, in other words when the child is instantiated.

Any ToolBars, MenuBars or StatusStrips (or ???) that may be anchored in the
frmParent will also need their height or width added to the size of frmChild
before setting frmParent's ClientSize

I'm not completely sure, but you might also look into frmParent.AutoSize and
frmParent.AutoSizeMode, if these will do what you want then it will be much
more eloquent.

So with no other anchored controls in the parent form, your code will look
something like this:

private void NewChildForm()
{
Form child = new Form();
child.MdiParent = this;

this.ClientSize = child.Size;

child.Show();
}



Good Luck,
 
J

Jeff Johnson

How do you set the client size of an MDI parent to fit around a child
form? Breakpoints in the constructor and load event handler show the child
size to be already modified to fit into the parent; the child's size does
not match what shows in the Designer. I suppose the real question might
be how do you determine the size of the child window or keep the parent
from changing it first?

Rethink your design. Please. I know it requires more work, but make the
child window flexible. Let it scroll, or rearrange its contents to fit the
size of its parent, and not vice versa. If what you have is by necessity
totally inflexible then I think MDI is probably not the direction you should
be going in the first place.
 
A

Abby Brown

Jeff Johnson said:
Rethink your design. Please. I know it requires more work, but make the
child window flexible. Let it scroll, or rearrange its contents to fit the
size of its parent, and not vice versa. If what you have is by necessity
totally inflexible then I think MDI is probably not the direction you
should be going in the first place.

It is not possible to change the design. I solved the problem by setting
the
parent size before setting the child to maximize. Apparently, I was
misreading
some of the watch numbers which exacerbated the situation.

Thanks to those who responded,
Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top