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


Hi everybody,

I'm new with VB and have a small problem with resizing.
I have a mdiForm that contains frmCube as a child.  frmCube only as an activeX call DynamiCube.  This Cube is called in my code DCube1.  It consist mainly of a pivot table with it's data.  I want the user to be able to resize the frmCube so the DCube1 size always follow.  So here's what I've tryed :

Private Sub Form_Load()'frmCube load
    iFrmHeight = Me.Height
    iFrmWidth = Me.Width
    iFrmTop = Me.Top
    iFrmLeft = Me.Left
    iCubeLeft = DCube1.Left
    iCubeWidth = DCube1.Width
    iCubeTop = DCube1.Top
    iCubeHeight = DCube1.Height
End Sub

Private Sub Form_Resize()
Dim diffWidth As Double
Dim diffHeight As Double
Dim diffTop As Double
Dim diffLeft As Double

On Error Resume Next
diffWidth = Me.Width - iFrmWidth 'Width courant- precedent
diffHeight = Me.Height - iFrmHeight
diffTop = Me.Top - iFrmTop
diffLeft = Me.Left - iFrmLeft

'0.090909 = DCube.Left / frmCube.Left        
DCube1.Left = iCubeLeft + diffLeft * 0.090909  
DCube1.Width = iCubeWidth + diffWidth * 0.95542
DCube1.Top = iCubeTop + diffTop * 0.096969
DCube1.Height = iCubeHeight + diffHeight * 0.924242
    iFrmWidth = Me.Width        'update
    iFrmHeight = Me.Height
    iFrmTop = Me.Top
    iFrmLeft = Me.Left
    iCubeLeft = DCube1.Left
    iCubeWidth = DCube1.Width
    iCubeTop = DCube1.Top
    iCubeHeight = DCube1.Height
End Sub

The problem I have is that the DCube1 do resize but I lose the scroll bar on the bottom and on the right of the Cube.
I've also tried with the DCube1.move method but it does the same.  I dont even know if that's how I'm suppose to do it...I'm open to other suggestion!


1 Solution
You can make the borders of your form a bit larger.
Or subtract the size of the scrollbars of the size of the cube.
If the user shrinks the form then the control will not shrink enough.  For example, with
DCube1.Width = iCubeWidth + diffWidth * 0.95542
assume that diffWidth is positive; you're fine, because this means that the control will grow slightly less than your form, still exposing the scroll bars.  However, if diffWidth is negative, then your control will shrink slightly less than your form, hiding the scroll bars.

See if this works:
if diffWidth < 0 then
DCube1.Width = iCubeWidth + diffWidth * 1.04458
DCube1.Width = iCubeWidth + diffWidth * 0.95542
If it's always fills the form then use

DCube.With = Me.ScaleWidth
DCube.Height = Me.ScleHeight
DCube.Left = 0
DCube.Right = 0

Yes VincentLawlor hit the nail on the head. The scalewidth is your bit.

Here are some more tips:

1) Correct the standard resize bug like what youve got.

Always put the following at the top of your form resize:

If Me.WindowState=vbminimized then exit sub

2) Always test the form With a minimize and a maximize and then back to normal.

3) Create a command button and place your resize code in the command button to test.  The form resize disables some objects making it hard to debug, like the mouse, for example.

When working put the code back into the resize.

This will stop the system becomming unstable which it can do in a resize event. And you loose your changes when you have to reboot.

4) Cool Enhancement to item 3 so that your form resize code will not cause your system to hang.

For a real professional approach.

If you have a complex resize wich make takes more than a few 1000ths of a second to complete, change your form resize to fire a timer.  In this way your application won't hang.  As Windows will call Form_Resize each time the mouse is moved, when in resize mode.

Sub Form_Resize()


End Sub

Sub timerResize()

Static ResizeTime as single
Dim ResizeStart as single

if ResizeTime<.001 then ResizeTime=.001

if timer-lastresize<ResizeTime then exit sub



' Now call the invisible Command button where you placed your your code to test the resize.
' In practive you would give the button a better name e.g. SUBResize (as Command1 is a bit of a naff name).

Call SUBResize.Click

ResizeTime=(Timer-ResizeTime)*1.5 ' allow some time for other windows functions and timers

End Sub

richardferronAuthor Commented:
Thank's Vincent it's exactly what I needed.  Thank's also to inthedark who completed the answer with excellent comments!  I would've like to give points to you both but it does'nt seem possible. Sorry inthedark .  

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.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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