Re-Sizing Forms
Normally, when you re-size a form,
the objects on that form stay where they are.
Most users would prefer that they re-size
and/or re-position themselves in some logical manner.
Visual Basic
| Delphi
| C++ Builder
| Java
| Windows API
Visual Basic 6.0
ResizeControls.bas
contains routines to control the location of (pin) UI Objects
when a form is re-sized.
From the main form
Call Init_Pin_Array first
Call Init_Pin_UIObjects once for each object
For each additional form
Call Set_FormDefaults first
Call Init_Pin_UIObjects once for each object
In each form, call ResizePin_UIObjects from the form's Resize event
Normally, objects always keep the same distance from the top and left.
These routines allow you to keep a fixed number of pixcels from the bottom or right.
In addition, some objects can be stretched so that the right edge
keeps a constant distance from the right hand edge, or
so that the bottom edge keeps a constant distance from the
bottom of the form.
These are controlled via the following constants.
Enum Resize_Constants
Stretch_Width
Stretch_Height
Pin_To_Bottom
Pin_To_Right
End Enum
Technique Based on "object.move"
An alternate way to do this
(which uses much less code)
is used in a
BoonDog example.
Search the listings for Form_Resize().
(I don't know exactly what the variable ScaleWidth
refers to.)
Basically, this code uses object.move
to re-size the objects.
Delphi
In Delphi, these options are trivial.
All components are derived from TControl which
provides
- Align - none, top, bottom, left, right, client
- Anchors - top, bottom, left, right
- Constraints - maximum and minimum width and height
Some components publish all 3 properties
(ie, make them available at design time),
others don't.
For instance
- TForm, TPanel, TLabel, TMemo publish all 3
- TEdit, TButton publish Anchors and Constraints
If the control is Anchored to opposite sides (left and right or top and bottom) then the control will stretch when the form is re-sized.
The align property controls both position and size.
alNone | |
|
alTop | | Width is equal to the container's width
|
alBottom | | Width is equal to the container's width
|
alLeft | | Height is equal to the container's height
|
alRight | | Height is equal to the container's height
|
alClient | | Height and width are equal to
the container's height and width
|
When you want to keep a bunch of related objects (usually buttons)
centered, you simply place them in a container
and then center the container.
On the negative side, once you've set these parameters,
they are active (functional) at design time.
Thus, any attempt to re-size a form
while it is being designed
will make the controls stretch and move.
Also, if the form is made narrow enough to display a
horitoztal scroll bar,
then the TRichEdit control with verticle stretching enabled
will not display correctly.
C++ Builder
Same as Delphi.
Java
Windows API
Not applicable.
Author: Robert Clemenzi -
clemenzi@cpcug.org