RESIZE.BAS User's Guide
 |
|
The Resize module is used like a stretch control to maintain
the relationship between controls on a form as the user resizes it,
except Resize is much better.
Resize give a much better feel.
It gave me a noticeable edge over others.
It was written in VB3 before Windows95 arrived
yet it's sill just as useful.
First let's go over the steps for using Resize.
|
1
|
Define the relationships of objects
This is done by calling the AddChild, AddContents,
and AddPane methods from the Form_Load event.
In each relationship, the movement of one object
is expected to effect the size and position of the other.
This is referred to as a parent/child relationship.
Examples are provided below.
Step 2 shows how to enforce these relationships.
AddChild
Establishes a relationship between a form and a control in it.
Call AddChild(ChildControl, Move&Size)
AddContents
Establishes a relationship between
a container control other than a form and a control in the container.
Call AddContents(ContentsControl, Move&Size, ContainerControl)
AddPane
Establishes a Parent/Child relationship between
two sibling controls (same parent or container).
Call AddPane(PaneControl, Move&Size, SashControl)
See Reference for more details on these instructions.
| |
2
|
Maintain the relationships
This is done by calling the EnforceForm,
EnforceContainer, and EnforceSash methods.
EnforceForm is usually called from the Form_Resize event.
EnforceContainer is usually called right after ContainerControl
is moved which is usually caused by EnforceForm or EnforceSash.
The order in this case is important.
Call EnforceForm(Me)
Call EnforceContainer(ContainerControl)
EnforceSash is usually called right after SashControl.Move method is called.
This is usually in a procedure called from various DragDrop events.
Call EnforceSash(SashControl)
| |
3
|
Clean Up
| RemoveForm |
Simply call RemoveForm(Me) in every Form_Unload event.
It removes all the references to parent controls
and child controls in that form from inside the Replace module.
This is a big memory saver
especially if the form gets loaded and unloaded frequently.
Private Sub Form_Unload(Cancel As Integer)
Call RemoveForm(Me)
End Sub
| | RemoveControl |
RemoveControl is for the special case when a control gets unloaded
but the form in is in does not get unloaded.
In this situation, call RemoveControl right after the unload instruction.
It removes all relationships where that control is either the parent or the child.
This prevents errors when Enforce instructions are called.
|
| |
4
|
Movement Correction (optional)
The user might resize a form or move a Parent
in such a way as to make children
distorted or unusable. It might be obvious to the user
to move whatever back a bit. Or you might prefer to
prevent the user from doing such a thing in the
first place. Such movements can be corrected in two
basic ways. In code, you can define limitations that
you can check before calling EnforceForm, EnforceContainer, and EnforceSash.
If the limits are exceeded, then you can programatically
move the form or control back within the limitations.
The second method is to use the CorrectionX and
CorrectionY global variables.
For example:
Private Sub CommonDrop(Source As Control, _
ByVal X As Single, ByVal Y As Single)
Do
CorrectionX = 0
Source.Move X
Call EnforceSash(Source)
X = X + CorrectionX
Loop Until CorrectionX = 0
End Sub
Sub Form_Resize()
If Me.WindowState = MINIMIZED Then
Exit Sub
End If
Call EnforceForm(Me)
If CorrectionX > 0 Or CorrectionY > 0 Then
'Move causes a cascading event.
Me.Move Me.Left, Me.Top, _
Me.Width + CorrectionX, _
Me.Height + CorrectionY
End If
End Sub
Watch out for cascading events. If you move a form
in the From_Resize event, the event will start a second
time before completing the first. Exit the event right
after calling the Move method. Note that CorrectionX and
CorrectionY are in the ScaleMode of the parent's size
and position properties. So, no conversion is needed.
CorrectionX and CorrectionY can be negative
for Splitter Bar type SashControls.
CorrectionX and CorrectionY are set to zero by EnforceForm.
The sign of CorrectionX and CorrectionY indicate the direction.
For example, if CorrectionX is positive after EnforceForm,
then widen the form more.
| |
|
Remarks
The ScaleMode of every form and ContainerControl must be Twips or Pixels.
If a ContainerControl does not have a ScaleMode property,
then it's assumed to be Twips.
If a SashControl is a lightweight/graphic control,
then the ScaleMode of the parent form is used.
If this Resize module finds a situation it cannot handle,
it puts a message in RepositionMessage.
An error is not generated since many of these problems
are not so bothersome to the user as to require such a measure.
These messages are usually generated while
testing or debugging an application.
So, RepositionMessage can be very useful in these cases.
If a VB error occurs in this component module,
it can be trapped by the host/client application.
The child controls (which are ChildControl, ContentsControl, and
PaneControl) must provide write access at run-time to Left and Top properties.
If RE_HEIGHT option is used, then write access to
Width and Height properties is needed at run-time.
If RE_WIDTH option is used, then write access
to the Width property is needed at run-time.
|

|
|
|