Resizing Algorithm for Docked Objects

Posted on 2004-09-07
Last Modified: 2010-05-02
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.


Question by:KarlPurkhardt
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 18

Expert Comment

ID: 11998552
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.

LVL 15

Expert Comment

ID: 11998595
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.

Author Comment

ID: 12000949
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?
LVL 15

Accepted Solution

SRigney earned 250 total points
ID: 12005410
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.

Author Comment

ID: 12011249
Yep that did it, thanks for your input :)

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question