Setting MDI Parent Size To Fit Around A Child Form

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 


0
Abby
12/28/2009 1:12:14 AM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

3 Replies
2340 Views

Similar Articles

[PageSpeed] 35

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,
-- 
Roger Frost
Logic Is Syntax Independent



"Abby Brown" <abbybrown@charter.net> wrote in message 
news:esXiJr1hKHA.5520@TK2MSFTNGP06.phx.gbl...
> 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
> 
0
Roger
12/28/2009 2:03:46 AM
"Abby Brown" <abbybrown@charter.net> wrote in message 
news:esXiJr1hKHA.5520@TK2MSFTNGP06.phx.gbl...

> 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. 


0
Jeff
12/28/2009 2:49:39 PM
"Jeff Johnson" <i.get@enough.spam> wrote in message 
news:Oh0$8z8hKHA.2188@TK2MSFTNGP04.phx.gbl...
> "Abby Brown" <abbybrown@charter.net> wrote in message 
> news:esXiJr1hKHA.5520@TK2MSFTNGP06.phx.gbl...
>
>> 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.

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


-1
Abby
12/28/2009 9:23:10 PM
Reply:

Similar Artilces: