Resizing an MDI child withim the MDIParent.

G

Guest

Hi. I have been trying unsuccessfully to resize an MDI child form to fit
exactly into the MDIParent and cover the whole of the ClientRectangle.
All code that I have written using the ClientRectangle shows the child form
as a bit to big and the MDI displayes scroll bars. .ClientSize.Width and
..ClientSize.height seem to return larger values than the Client area really
is.
Docking, which does give the correct result. is not an alternative as the
displayed child form cannot then be manipulated by the user to other
positions in the MDI client area.

Help would be appreciated.
 
B

Bob Powell [MVP]

As well as Fox's recommendation you should also remember that the main form
is not actually the parent of the MDI child form. This role is undertaken by
the MDIClient which is owned by the main form. You should use this control
to provide information on main form areas etc.

There is an article in Windows Forms Tips and Tricks that explains how to
put a background on the MDIClient. This will show you how to obtain a
reference to that object.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
A

Amnon

Well, maximizing would be very much like using the Docking property.

The user would not be able to move the MDIChild around in the client area.

In VB6, the code is so trivial and it is causing me so much work in VS2005.

Very disheartening

Amnon
 
A

Amnon

Well thank you Bob.

The whole MDI child resizing stuff has become a real nightmare.

I implemented parts of your code to get the right result ONCE. Then, if I
regenerated the same MDI child form, it seems that hidden mechanisms force
the second MDI client to be 'cascaded' relative to the visible 'child area'
of the MDI form. Do I have to look in the controls collection for the first
MDIClient by searching for its handle.

Then, what happens when I want a second different MDIChild form to be
generated. One on top of the other - not maximised and not 'docked'

How do I cancel the seeming default mechanism of the MDIParent to cascade
all subsequent instances IF this is indeed what is happening.

What a nightmare.

I would perhaps suggest that Microsoft does not want developers to use MDI
projects. Or at least in the way we used them in VB6.

I include the following code:

Public Function ReturnMDIClient(ByVal frm As System.Windows.Forms.Form) As
System.Windows.Forms.Control
Dim c As Control
For Each c In frm.Controls
If TypeOf c Is MdiClient Then
ReturnMDIClient = c
End If
Next c

End Function

AND

Dim frmBrowse As New Form1
Dim MDIClient As System.Windows.Forms.Control

MDIClient = ReturnMDIClient(frmMain)
frmBrowse.MdiParent = frmMain
frmBrowse.Left = 0 'MDIClient.Left
frmBrowse.Top = 0 'MDIClient.Top
frmBrowse.Width = MDIClient.Width - 5
frmBrowse.Height = MDIClient.Height - 5
frmBrowse.Show()

The first time that the MDIChild was generated, it fitted nicely into the
client area but the second time with the same instance of the frmMain, the
..top and .left values were displaced as if it were cascaded relative to the
first.

I tried to send this email with a screen shot of the cascading effect BUT
there was an error

Awaiting your comments

Amnon
 
M

Martin Stainsby

Amnon said:
Well thank you Bob.

The first time that the MDIChild was generated, it fitted nicely into the
client area but the second time with the same instance of the frmMain, the
.top and .left values were displaced as if it were cascaded relative to
the
first.

Try setting the MDIChild's StartPosition to manual.
 

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