[RESOLVED] MDI Parent Client Size calculates incorrectly-VBForums
Results 1 to 7 of 7

Thread: [RESOLVED] MDI Parent Client Size calculates incorrectly

  1. #1

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Resolved [RESOLVED] MDI Parent Client Size calculates incorrectly

    http://www.vbforums.com/showthread.php?t=613612

    The link above is a thread showing the application I'm working on. (2008 Pro)

    I have since created an MDI Parent form which holds my 16 camera forms. What I am having trouble with is dividing the MDIParent's Width and Height by 4, to display 4 equal height/width camera forms within it.

    I've tried all the available properties (Rectangle, ClientArea, etc) and none seem to calculate correctly. Using Me.Width and Me.Height ALMOST worked, but again, it was about an inch too skinny and short.

    What do I need to do in order to retrieve the exact size of the MDIParent's Client Area?

    Thanks.

    I did search, but did not find much in the way of a resolution.

  2. #2
    PowerPoster formlesstree4's Avatar
    Join Date
    Jun 2008
    Location
    On the Internet
    Posts
    3,243

    Re: MDI Parent Client Size calculates incorrectly

    Will the Parent be maximized at all times?

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,133

    Re: MDI Parent Client Size calculates incorrectly

    The child forms are hosted inside an MdiClient object. Get the Width and Height of that.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  4. #4
    PowerPoster formlesstree4's Avatar
    Join Date
    Jun 2008
    Location
    On the Internet
    Posts
    3,243

    Re: MDI Parent Client Size calculates incorrectly

    @JMC, I thought he already tried that?

    I've tried all the available properties (Rectangle, ClientArea, etc) and none seem to calculate correctly.
    .
    Doesn't ClientArea fall in that category? Or am I missing something about MdiParents.

  5. #5

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: MDI Parent Client Size calculates incorrectly

    I have not tried the MDIClient. I only tried the properties of the MDIParent form itself, wasn't aware of the MDIClient object.
    I don't have the solution on this computer, but will try it when available.

    The MDIParent won't be "maximized" per se, but will remain a fixed size at runtime. the camera forms within it will always fill this parent form which may be in a 2x2 format, a single form, 4x4 format or selected cameras.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,133

    Re: MDI Parent Client Size calculates incorrectly

    Just did a bit of experimentation. The trick is that the MdiClient occupies the form's ClientRectangle but it has a 3D border of its own, so you have to use its ClientSize too. I just tried this and it worked as expected:
    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         For i = 1 To 16
    5.             With New Form
    6.                 .MdiParent = Me
    7.                 .Show()
    8.             End With
    9.         Next
    10.     End Sub
    11.  
    12.     Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
    13.         Me.ArrangeChildren()
    14.     End Sub
    15.  
    16.     Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeEnd
    17.         Me.ArrangeChildren()
    18.     End Sub
    19.  
    20.     Private Sub ArrangeChildren()
    21.         Dim containerSize = DirectCast(Me.Controls(0), MdiClient).ClientSize
    22.         Dim childWidth = containerSize.Width \ 4
    23.         Dim childHeight = containerSize.Height \ 4
    24.         Dim children = Me.MdiChildren
    25.  
    26.         For index = 0 To children.GetUpperBound(0)
    27.             children(index).SetBounds((index Mod 4) * childWidth, _
    28.                                       (index \ 4) * childHeight, _
    29.                                       childWidth, _
    30.                                       childHeight)
    31.         Next
    32.     End Sub
    33.  
    34. End Class

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: MDI Parent Client Size calculates incorrectly

    That worked a charm jmc!! and it's a helluva lot cleaner than the way I was doing it to set the .Top and .Left properties. The SetBounds Method allows you to set all for parameters at once? I completely removed my .Top and .Left Select Case thing and they still size perfectly.

    I have a new question (I'll post in a new thread) regarding dis-allowing the movement of these forms
    Screenshot:
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.