• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 857
  • Last Modified:

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?
0
ljmilano
Asked:
ljmilano
  • 4
  • 3
1 Solution
 
ChloesDadCommented:
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
0
 
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.
0
 
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
                f2.Show()
            End If
        Next
    End Sub
 
End Class

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
This is what it looked like:
MdiChildSizing.jpg
0
 
ljmilanoAuthor Commented:
Hi Genius....you're not going to believe this, but I get the same results...here'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
        ChildForm.Show()
More help is greatly appreciated...thanks..


0
 
Mike TomlinsonMiddle 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!  =)
0
 
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.
0
 
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:
http://msdn.microsoft.com/en-us/library/system.windows.forms.mdiclient.aspx

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

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now