Resizing Algorithm for Docked Objects

Im currently working on a docking area that allows me to dock objects (as many as is needed, for example three objects).  The problem is im struggling to create an algorithm that resizes each of the docked objects cleanly, for example in Visual Basic 6.0 you can resize the MDI and the right docked objects (Project Explorer, Properites Window and the Form Layout Window - by default) resize with it.  

To expand a little more, if you resize the VB MDI (make it smaller) the docked objects shrink equally, and when you exapnd the MDI again, everything expands equally and the docked objects return to their origianal positioins and size (the positions and size they were before resizing occured) - this is the sort of effect I really want.


Who is Participating?

Improve company productivity with a Business Account.Sign Up

SRigneyConnect With a Mentor Commented:
A better idea would be to keep a percentage of the dockable area that each takes up.

If you have 3 items docked with a dockable area of 100

1st = 25 = 25%
2nd = 50 = 50%
3rd = 25 = 25%

Then you resize to 90, you would want to keep the same ratio for the docked areas.
1st = 22.5
2nd = 45
3rd = 22.5

Then when you go back to 100 as your size the ratio is still the same.
A possible wat to do this is in the resize event of your form you just take the the Height and Width of the form and proportionally allocate it to the controls on you form.

e.g in the Form_Resize event:
Frame1.Width = Me.ScaleWidth \ 3
Frame2.Left = Frame1.Width
Frame2.Width = abs(Me.ScaleWidth - Frame2.Left)

There is also a control called Frameplus. I recommend using this for dockable forms. It's certainally worth a look and they have an evaluation version.

What you would want to do, is each dockable area needs to be in charge of resizing items within it in regards to the size of the dockable area.  When you resize the main form you also need to add code to shrink or grow the dockable areas accordingly (which is what JR provided).   As you shrink and grow this area the resize code of the dockable area fires off and it will then position and size the items within it accordingly.
KarlPurkhardtAuthor Commented:
Thanks for the input, but i dont think i made myself clear.

Ive got something already done similiar to what has been mentioned above, the problem is, for example lets say the height of dockable area is 100, in that dockable area there are three docked objects, the one at the top has a height of 25, the one in the middle has a height of 50 and the bottom object has a height of 25.  

Now with the code i have when i resize the dockable area the docked objects resize but they do so based on the height of the dockable area, so lets say i resized the height of the dockable area to 90, the three objects would then be resized to a height of 30 each (90 / 3), so if i then resized it back to 100, rather than restoring the default heights (which as mentioned above were 25, 50 and 25) the heights restored would be 33.3 (100 / 3).

Im not sure if Ive explained that clear enough, its hard to put it into words.

I have posted the code below so you can get an idea of what I have done already, this code will no doubt need to be replaced though.

The following code is currently in my Dock Area Resize event.

<-- CODE START -->

' loop through all the docked items
For intLoop = 0 To m_NumDocked - 1
   ' specify a new height
   m_Docked(intLoop).Height = UserControl.ScaleHeight / 3
   ' adjust the top position of all docked objects except the
   ' first - the first is the object at the top and therefor
   ' does not need to be moved
   If intLoop > 0 Then
      ' set the top of this object to the bottom of the last object
      ' plus the spacer width
       m_Docked(intLoop).Top = (m_Docked(intLoop - 1).Top + _
                                              m_Docked(intLoop - 1).Height) + _
   End If
   ' if this is the last object (at the bottom) then make sure
   ' the height stretches to the bottom of the dockable area
   If intLoop = (m_NumDocked - 1) Then
      m_Docked(intLoop).Height = ((UserControl.ScaleHeight - 30) - _
   End If

next intLoop

<-- CODE END -->

Ive had an idea of how to achieve what im after, which I will try later.  What i thought was if i find how much the form has been resized, then divide that number by the docked objects, I can then use that figure to resize the objects evenly, and in theory when the form is resized (back to its original size) the procedure is reversed and the docked objects should return to their original size and positions, if you understand what I mean?
KarlPurkhardtAuthor Commented:
Yep that did it, thanks for your input :)
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.