Solved

Form_Resize

Posted on 2001-07-12
5
495 Views
Last Modified: 2007-11-27
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!

Thank's

Richard
0
Comment
Question by:richardferron
5 Comments
 
LVL 11

Expert Comment

by:Otana
ID: 6277647
You can make the borders of your form a bit larger.
Or subtract the size of the scrollbars of the size of the cube.
0
 

Expert Comment

by:JimBarron
ID: 6277688
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
else
DCube1.Width = iCubeWidth + diffWidth * 0.95542
endif
0
 
LVL 4

Accepted Solution

by:
VincentLawlor earned 100 total points
ID: 6277932
If it's always fills the form then use

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

Vin.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6278290
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()

LastResize=Timer
timerResize.Interval=100

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

timerResize.Interval=0

ResizeStart=Timer

' 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


0
 

Author Comment

by:richardferron
ID: 6280668
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 .  

Richard
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 …
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now