Solved

Resizing Algorithm for Docked Objects

Posted on 2004-09-07
5
280 Views
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.

Thanks.

Karl
0
Comment
Question by:KarlPurkhardt
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:JR2003
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)
'etc...

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.

0
 
LVL 15

Expert Comment

by:SRigney
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.
0
 
LVL 4

Author Comment

by:KarlPurkhardt
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) + _
                                               vbResizeStripHeight
   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) - _
                                                 m_Docked(intLoop).Top)
   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?
0
 
LVL 15

Accepted Solution

by:
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.
0
 
LVL 4

Author Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

861 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