How to resize an MDIChild to fit exactly the MDIParent forms client region?

I am trying to size MDIChild forms within the MDIParent forms client region.  I have found code that is supposed to work but does exactly what it says it prevents, so it's useless.  I am trying this code:
(  Me.Size = MdiParent.ClientSize - MdiParent.DefaultMargin.Size  ) but I am still getting the scroll bars on my MDIChild form.  How do I eliminate the MDIChild form scroll bars?
Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
That is NOT the same code that I used...  =\

Note that I used a LOOP to iterate the controls collection of the MdiParent to find the "MdiClient" instance.  Then I set the size of the child form to the size of THAT control...and not the Form itself which is what you did with "Me.ClientSize".

Look again CLOSELY at my code please!  =)
I may be stating the obvious, but why not maximise the child form.

You will get scroll bars on the child form if there are controls outside the visible area. You can use the Dock and or Anchor properties of the controls to ensure that controls always fit where you want them to in a form no matter how it is resized
ljmilanoAuthor Commented:
Hi ChloesDad, thanks, but that's not really what I'm looking for.  I've seen this comment all over the internet, and I'm sure you have... "it used to be so easy in VB6".  I like the look and feel of sizing it without maximizing it, and now, I really just want to know how to do it because I can not figure it out.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Mike TomlinsonMiddle School Assistant TeacherCommented:
This worked for me:
Public Class Form1
    ' ...this is the MdiParent form...
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each ctl As Control In Me.Controls
            If TypeOf ctl Is MdiClient Then
                Dim f2 As New Form2
                f2.StartPosition = FormStartPosition.Manual
                f2.Size = ctl.ClientSize
                f2.Location = New Point(0, 0)
                f2.MdiParent = Me
            End If
    End Sub
End Class

Open in new window

Mike TomlinsonMiddle School Assistant TeacherCommented:
This is what it looked like:
ljmilanoAuthor Commented:
Hi're not going to believe this, but I get the same's my code, I still get the scroll bars.
        ' Create a new instance of the child form.
        Dim ChildForm As New frmImport

        ChildForm.StartPosition = FormStartPosition.Manual
        ChildForm.Size = Me.ClientSize
        ChildForm.Location = New Point(0, 0)
        ChildForm.MdiParent = Me
More help is greatly appreciated...thanks..

ljmilanoAuthor Commented:
Hi Idle Mind:  Got It!!!!
Couple of points.  I actually put that code in a procedure that loads the frmImport from a menu option on the MDIParent form.  So, I figured I already had the MDIChild instance and wouldn't have to search through a loop for it...which means I didn't read your code correctly, I needed the MDIClient.  Sorry, I was looking at it after a long day.  Thanks for your help.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Glad it was helpful!  The MdiClient class is one of those things you would be unlikely to find on your own just reading the help in the documentation:

I picked it up myself a long time ago here on EE...  =)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.