Solved

Form_Resize

Posted on 2001-07-12
5
503 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cannot enter table caption text in Word protected document 6 125
VBA error replacing data 6 40
Windows 10 start screen issues 9 55
VBA Shell can't Find Word document 11 94
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 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